ExercisesHooks
useFindWordsExercise
Word search exercise
Find hidden words by selecting cells. Tracks found words and selection; validates on release. Used by FindWords.
Key returns
| Property | Description |
|---|---|
displayGrid | Grid for rendering |
wordResults | Validation result per word |
selectedCells | Currently selected cells |
setSelection | Set selection state |
commitSelection | Validate and commit selection |
reset | Reset to initial state |
Example
import { useFindWordsExercise } from '@bside-tech/tbx-ui/hooks';
// solutionGrid: letters = word cells; '' or ' ' = random filler
const solutionGrid = [
['C', 'A', 'T', ' '],
[' ', ' ', ' ', ' '],
['D', 'O', 'G', ' '],
];
const words = [
{ startRow: 0, startCol: 0, direction: 'horizontal', solution: 'CAT' },
{ startRow: 2, startCol: 0, direction: 'horizontal', solution: 'DOG' },
];
const {
displayGrid,
wordResults,
selectedCells,
setSelection,
clearSelection,
commitSelection,
reset,
} = useFindWordsExercise({
solutionGrid,
words,
seed: 42, // stable random letters for empty cells
});
// User drags from (0,0) to (0,2) to select "CAT"
setSelection([0, 0], [0, 2]);
commitSelection(); // validates selection, marks word found, clears selection