ExercisesHooks
useFillBlanksExercise
Fill-in-the-blank exercises
Supports multiple valid answers per blank via solution array. Optional normalize function for comparison. Used by InlineText and InlineChoices.
Key returns
| Property | Description |
|---|---|
answers | Current answers per blank |
setAnswer | Set answer for a blank |
isCorrect | Whether all blanks match |
check | Validate answers |
reset | Reset 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