Training Grounds
Search Hook Ignores What You TypeBlack Belt
+50 Ki
Description

A custom hook filters a list based on a query passed in as an argument. Changing the query from the parent updates the filtered results.

Anomaly

Type in the search box — the filtered list never changes after mount. The hook only runs the filter once on first render.

Constraint
Do not inline the hook logic into the component
Hint

The hook receives query as an argument — does it respond when that argument changes?

Consult the SenseiOnly for those truly stuck · Flip to reveal

The hook receives query as an argument — does it respond when that argument changes?

Loading editor…
Correct Solution
Loading...

Why this fixes it

`useFilter` closed over `query` at the time the effect was created — with an empty dependency array, the effect ran once on mount with the initial empty string and was never recreated, so every subsequent call to `useFilter` with a new `query` value was silently ignored by the effect inside it. Adding `query` to the dependency array inside the custom hook tells React to re-run the effect whenever the argument passed into the hook changes, giving the filter logic a fresh closure on each update. The fix works because custom hooks are plain functions that participate in React's dependency tracking the same way component-level effects do — the hook boundary does not insulate the effect from needing its dependencies declared.

Expected OutputGoal State
Your OutputLive