QuizNot attempted
When useCallback helps
1–4 to choose, Enter to submit
Show answer & explanation
Correct answer:
- When it is passed to a
React.memochild, or used in a dependency array
useCallbackonly keeps the same function reference, which helps only when something compares references: aReact.memochild's props or an effect/memo dependency array.- Not 'always faster': otherwise it is extra work and memory each render.
- Not 'DOM handlers only': DOM elements don't care about handler identity at all.
- Not 'no props': irrelevant
- it is about who receives the function.
useCallback(fn, deps)equalsuseMemo(() => fn, deps).