TBX Docs
ExercisesHooks

useFillBlanksExercise

Fill-in-the-blank exercises

Supports multiple valid answers per blank via solution array. Optional normalize function for comparison. Used by InlineText, InlineChoices, and InlineDragAndDrop. Optional onSuccess / onFailure run after check() — see Check callbacks.

Key returns

PropertyDescription
answersCurrent answers per blank
setAnswerSet answer for a blank
isCorrectWhether all blanks match
checkValidate answers
resetReset to initial state

Example

import { useFillBlanksExercise } from '@bside-tech/tbx-ui/hooks';

// "The cat ___ on the ___." → blanks expect ["sat"|"sits", "mat"|"floor"]
const { answers, setAnswer, isCorrect, check, reset } = useFillBlanksExercise({
  solution: [
    ['sat', 'sits'],      // blank 0: either valid
    ['mat', 'floor'],    // blank 1: either valid
  ],
  normalize: (v) => v.trim().toLowerCase(),
  checkOn: 'manual',
});

// Set blank at index 0
setAnswer(0, 'Sat');

// Set blank at index 1
setAnswer(1, 'mat');

// Validate when user submits
check();

// answers[i] gives current value for blank i

On this page