useCallback Hook Flashcards
7 cards from real React practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.
Read the first 7 useCallback Hook flashcards as text
What does the useCallback hook primarily do in React?
Answer: It memoizes a callback function so it only changes if its dependencies change
useCallback returns a memoized version of the callback that only changes when one of its dependencies has changed, preventing unnecessary re-renders.
What is the correct syntax for using useCallback?
Answer: useCallback(fn, [deps])
useCallback takes a callback function as its first argument and a dependency array as its second argument.
When is it most beneficial to use useCallback?
Answer: When passing a callback function as a prop to a child component wrapped in React.memo
useCallback is most useful when passing callbacks to child components wrapped in React.memo, preventing unnecessary re-renders when the parent re-renders.
What happens if you pass an empty dependency array [] to useCallback?
Answer: The callback is memoized once and never changes
An empty dependency array means the memoized callback has no dependencies, so it's created once on mount and remains the same reference throughout the component's lifetime.
What is the key difference between useCallback and useMemo?
Answer: useCallback memoizes a function itself; useMemo memoizes the return value of a function
useCallback(fn, deps) is equivalent to useMemo(() => fn, deps) — useCallback returns the function, while useMemo returns the computed result of calling the function.
Which of the following is a common problem that useCallback helps solve?
Answer: Unnecessary re-renders of child components due to new function references on each render
Without useCallback, a new function reference is created on every parent render, causing child components (even those using React.memo) to re-render unnecessarily.
What is a 'stale closure' problem in the context of useCallback?
Answer: When a memoized callback captures outdated values from a previous render because dependencies were omitted
A stale closure occurs when you omit a value from the dependency array that the callback uses, so the callback holds a reference to the old value from a previous render.
Written and edited by Nathan Beja, founder of Practice Test Geeks, with AI assistance. We have not yet matched this exam's facts to an official source, so confirm fees, dates and rules with the exam body. Editorial policy