React hooks interview questions: useMemo and useCallback

Reviewed by Mark Dickie · Last updated

5 questions on this page you can answer and see marked on the spot. Go to the first one

React's useMemo and useCallback are hooks that cache a computed value and a function reference between renders, so children and effects can skip work. Interviewers use them to test whether you know when memoization pays off and when it only adds overhead. Most questions turn on dependency arrays, how React compares them with Object.is, and why React.memo does nothing when a parent passes a fresh function on every render.

When should you reach for useMemo or useCallback?

Hook or APIWhat it keeps between rendersInterview trap
useMemo(fn, deps)The value that fn returnsExpensive filtering recomputed on every render because deps changes each time
useCallback(fn, deps)The same function instance until deps changeWrapping a handler in useCallback but passing it to a child that is not React.memo
React.memo(Component)Skips a re-render when shallow-compared props matchAn inline object or array prop defeats the memo on every parent render
Missing dependencyNothing, so the closure reads a stale valueThe value looks correct until a prop changes and the old result sticks

Which hands-on exercises show you understand memoization?

  1. Filter a list of 5,000 rows inside useMemo, then time the render with the React Profiler with and without the hook.
  2. Pass an onClick from useCallback into a React.memo child, count its renders in React DevTools, then remove useCallback and count again.
  3. Omit a prop from a dependency array, reproduce the stale value, then fix it using the exhaustive-deps lint rule.
  4. Explain why React may discard a useMemo cache, and what that means for code that relies on the cached value for correctness.

Key facts

  • Tarmac has 11 React interview questions on this topic, 10 of them on this page, at difficulty 1–5 of 5.
  • Tarmac tracked 1,185 job postings asking for React in November 2026.
  • Roles asking for React advertise a median base salary of £75,000, across 477 job postings as of November 2026.
  • Tarmac last reviewed these React interview questions on 30 November 2026.

At a glance

Questions10 shown · 11 in the bank
Difficulty1–5 of 5
FormatsOrdering, Multiple choice, True / false, Fill in the blank, Find the bug, Multiple answer, Short answer, Flashcard, Coding exercise
Interactive1 run your code against tests, in the app

What you'll review

  1. usememo usecallback
  2. rerender causes

Practice questions

Try one before you open the answer. Pick an option and press Check; it's marked on the spot.

A component calls const total = useMemo(() => sum(items), [items]);. The component mounts, then re-renders with the same items array reference. Put these events in the order they happen.#

Put these in order

Show answer

With useMemo, the first render calls the calculation function and caches its result together with the dependency array. On a later render, React compares each dependency with its previous value using Object.is. If every dependency is unchanged, React returns the cached value and skips the calculation. If any dependency changed, React recomputes the value and caches the new result.

Why:

On the first render there is nothing cached yet, so React calls the calculation function and stores both its result and the dependencies it used. When the component renders again, useMemo runs again. React compares each dependency with its previous value using Object.is. Here items is the same reference, so React skips the calculation and returns the stored value. It can only compare after a render has stored something, and it can only reuse the cached value after the comparison finds the dependencies equal.

In React, what happens to a useMemo value if you leave out the dependency array entirely, as in const v = useMemo(() => compute(a));?#

Options

Show answer

If you call useMemo without a dependency array, React recomputes the value on every render, so you get no memoization at all. With no array, React has nothing to compare between renders. Pass [] to compute the value only once, or list the values the computation uses so it reruns only when one of them changes.

Why:

If no dependency array is passed, React has nothing to compare between renders, so useMemo recomputes the value on every render and you get no memoization. To compute the value only once you have to pass an empty array []. React does not infer dependencies at runtime. The ESLint rule react-hooks/exhaustive-deps can warn you about missing dependencies, but that check runs in your editor or build, not in React itself. The function also always runs on the first render, so v is never left undefined because of a missing array.

In React, useCallback(fn, deps) is equivalent to useMemo(() => fn, deps).#

Options

Show answer

Yes, useCallback(fn, deps) is equivalent to useMemo(() => fn, deps). useMemo caches the return value of its factory function. When that factory returns fn itself, the cached value is the function reference, which is what useCallback caches. Both give back a stable reference until a dependency changes. useCallback is just shorter syntax for memoizing a function.

Why:

The React docs say this directly: useCallback(fn, deps) is the same as useMemo(() => fn, deps). useMemo caches whatever its factory returns. If the factory returns the function fn, useMemo caches that function reference, which is exactly what useCallback does. In both cases the same reference comes back until a dependency changes. useCallback is just a shorthand for this common case.

_____ memoizes a computed value so it's only recalculated when its dependencies change, while _____ memoizes a callback function for the same reason.#

Show answer

**useMemo** memoizes a computed value so it's only recalculated when its dependencies change, while **useCallback** memoizes a callback function for the same reason.

Why:

useMemo caches a computed value; useCallback caches a function identity. useCallback(fn, deps) is equivalent to useMemo(() => fn, deps) — same idea, one returns a value, the other a function.

const SubmitButton = React.memo(function SubmitButton({ label, onClick }) { return <button onClick={onClick}>{label}</button>; }); function Form() { const [text, setText] = useState(''); return ( <> <input value={text} onChange={(e) => setText(e.target.value)} /> <SubmitButton label="Save" onClick={() => save(text)} /> </> ); } Every keystroke in the input causes SubmitButton to re-render too, even though label never changes and SubmitButton is wrapped in React.memo. Why?#

Options

Show answer

onClick={() => save(text)} allocates a brand-new function object on every render of Form, and React.memo's shallow comparison checks each prop with Object.is, which reports two distinct function objects as different even when they'd behave the same. So onClick reads as changed on every render and memo re-renders SubmitButton regardless of label. Wrapping the handler in useCallback (with stable dependencies) gives it a stable reference so memo can actually skip work when nothing meaningful changed.

Why:

Defining () => save(text) inline means every render of Form produces a syntactically new function object. React.memo's shallow comparison checks each prop with Object.is, and Object.is reports two distinct function objects as different even if they'd behave identically — so onClick always reads as "changed," and memo re-renders SubmitButton on every Form render regardless of label. Wrapping the handler in useCallback(() => save(text), [text]) (stable whenever text hasn't changed) would let memo actually skip work. b is wrong — memo compares any prop type with Object.is, not just primitives; it's just that objects and functions rarely stay reference-equal across renders. c is wrong — "Save" is a string primitive, and Object.is compares primitives by value, so it's equal across renders. d is a red herring: memo behaves identically regardless of function-declaration syntax.

A user changes the step input to 5 and clicks the button, but the count still goes up by 1. The button label correctly shows +5. Which line contains the bug?#

function Counter() {
  const [count, setCount] = useState(0);
  const [step, setStep] = useState(1);

  const increment = useCallback(() => {
    setCount(c => c + step);
  }, []);

  return (
    <div>
      <input type="number" value={step} onChange={e => setStep(Number(e.target.value))} />
      <button onClick={increment}>+{step}</button>
      <p>{count}</p>
    </div>
  );
}
Show answer

The bug is on line 7.

Why:

The dependency array on line 7 is empty, so useCallback keeps returning the function it made on the first render. That function closed over step when step was still 1. The functional updater c => c + step keeps count current, but it does nothing for step, which is still the stale value captured in the closure. The label re-renders with the new step, so it shows +5, but the click handler still adds 1. The fix is to change line 7 to }, [step]); so the callback is recreated whenever step changes. The react-hooks/exhaustive-deps lint rule flags this mistake.

When does wrapping a function in useCallback actually help?#

Options

Pick every one that applies.

Show answer

useCallback helps in two cases: when the function is passed to a React.memo-wrapped child that would otherwise re-render because a fresh function identity breaks its props comparison, and when the function is a dependency of another hook (an effect or memo) where a stable identity avoids needless re-runs. Everywhere else it only adds overhead — wrapping every function, or memoizing a plain inline handler with no memoized consumer, buys nothing.

Why:

useCallback only pays off when a stable function identity matters downstream: feeding a memoized child or serving as another hook's dependency. Applied everywhere it just adds overhead, and it does nothing useful for a plain inline handler with no memoized consumer.

What do useMemo and useCallback do, and when should you use them?#

Show answer

Both memoize across renders: useMemo caches a computed value and useCallback caches a function reference, recomputing only when their dependencies change. Use them to skip genuinely expensive recomputation or to keep a stable reference for a memoized child or an effect dependency — not as a blanket optimization, since they add overhead.

Why:

useCallback(fn, deps) is just useMemo(() => fn, deps). They matter mainly when a stable identity prevents wasted renders downstream or expensive work each render.

In React 18/19, useMemo and useCallback caches are not semantic guarantees. The React docs name two cases where React throws away a memoized value even though its dependencies did not change. What are they, and what does that mean for code that relies on memoization for correctness?#

Show answer
  1. Development-time file edit (Fast Refresh): when you edit the component's file in development, React discards its memo cache.
  2. Suspending during initial mount: if a component suspends during its first mount, React throws away its state and memo cache, in development and production. Whether later retries reuse any of that work is not guaranteed, so do not depend on it.

The docs also say React may add more cases in the future.

Consequence: treat memoization only as a performance hint. Code that must run exactly once, or that needs a stable identity for correctness, should use useRef, useState's lazy initializer, or module-level state. Do not build effect deduplication, subscriptions, or object identity checks on top of useMemo.

Why:

The React docs for useMemo say React will not throw away the cache without a specific reason, and they name two such reasons: editing the component's file in development (Fast Refresh) and suspending during the initial mount, in both development and production. Since the docs also allow future cases, memoization can only be a performance hint, so correctness must rely on refs, lazy state initializers, or module-level state rather than on a memoized value persisting.

Model how React 18's useMemo (and useCallback, which uses the same check) decides whether to rerun its factory, following React's actual areHookInputsEqual / updateMemo logic.#

Starter code

function memoRecomputes(renders) {
  // TODO: implement React's deps comparison
  return renders.map(() => true);
}

Your solution must pass

  • primitive change
  • empty deps compute once

This one is written and run, not read. Solve it in the app and your code is executed against these tests and the hidden ones.

Sources

The official documentation these questions are checked against:

Related interview questions

Job market

See react salaries and hiring demand from live job postings.

The other 1 question

This page shows 10 and marks what you pick. That's as far as a page can go. A free account opens the other 1 and keeps every answer. What you miss comes back until it's right: after a day, then at longer gaps.

Start with this topic

Free · the whole bank · 100 answers per 30 days, each marked with written feedback

Interview booked? Practise the job ad instead

What moved, monthly

One email a month when the bulletin comes out: what moved in the markets we track, and the new question topics we published. Confirm your address to join. Unsubscribe any time.