Skip to content

QuizNot attempted

When useCallback helps

When does wrapping a handler in useCallback actually prevent work?
1–4 to choose, Enter to submit
Show answer & explanation

Correct answer:

  • When it is passed to a React.memo child, or used in a dependency array
  • useCallback only keeps the same function reference, which helps only when something compares references: a React.memo child'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) equals useMemo(() => fn, deps).