ExercisesHooks
useMatchPairsExercise
Match pairs between two sets
Use for matching exercises (e.g. words to definitions). solution[i] gives the correct target index for origin item i. Used by ConnectPoints.
Key returns
| Property | Description |
|---|---|
connections | Current user connections |
setConnection | Set a connection from origin to target |
removeConnection | Remove a connection |
isCorrect | Whether all connections match the solution |
check | Validate answers |
reset | Reset to initial state |
Example
import { useMatchPairsExercise } from '@bside-tech/tbx-ui/hooks';
// Match words (origin 0,1,2) to definitions (target 0,1,2)
// solution[i] = correct target index for origin i
// e.g. "Apple"→0, "Banana"→1, "Cherry"→2
const {
connections,
setConnection,
removeConnection,
isCorrect,
check,
reset,
} = useMatchPairsExercise({
solution: [0, 1, 2], // origin 0→target 0, origin 1→target 1, etc.
checkOn: 'manual',
});
// User connects origin 0 to target 1
setConnection(0, 1);
// User clears the connection from origin 0
removeConnection(0);
// On submit
check(); // validates and sets isCorrect
// Reset all
reset();