Skip to content
tezvyn:

Child re-renders with unchanged props: function identity and useCallback fix

Source: react.devEasyHow cards are made

Child re-renders with unchanged props: function identity and useCallback fix

This tests reference equality and React memoization. A strong answer says inline functions recreate on every parent render, breaking React.memo, and uses useCallback with a correct dependency array. A red flag is ignoring identity or omitting dependencies.

What's really being asked

This question evaluates whether you understand referential equality in JavaScript and how React performs shallow prop comparisons for memoization. Specifically, it checks if you know that functions are objects in JavaScript and that a newly created function has a different identity even if its body is identical. It also tests whether you know how to use the useCallback Hook to preserve a function reference across renders when dependencies are stable.

The full answer

First, the candidate should identify the root cause: every time the parent renders, an inline function defined in the parent body is recreated, producing a new reference. Second, they should explain that if the child is wrapped in React.memo or extends PureComponent, the shallow prop comparison sees the new function reference as a changed prop and forces a re-render. Third, they should describe the fix: import useCallback from React, wrap the function definition at the top level of the component, and pass a dependency array containing every reactive value used inside the function. Fourth, they should note that useCallback returns the cached function when dependencies have not changed according to Object.is, and returns a new function otherwise.

The mistakes people make

A major red flag is saying the props are unchanged without explaining reference identity. Another is suggesting useCallback inside a loop or condition, which violates the Rules of Hooks. Candidates sometimes omit the dependency array or fill it incorrectly, which leads to stale closures or broken memoization. Some also incorrectly claim that useCallback prevents the parent from re-rendering; it only memoizes the function, it does not stop the parent render cycle.

What usually comes next

The interviewer might ask what happens if the dependency array is empty, how Object.is differs from deep equality, or when useCallback is unnecessary overhead. They may also ask how the React Compiler changes the need for manual useCallback, or how this pattern interacts with useEffect dependencies.

A concrete example

Imagine a Parent component with a state count and a child wrapped in React.memo. Parent renders a button with onClick defined as an inline arrow function that calls setCount. Even though the child receives no count prop, Parent passes handleLog defined as another inline arrow function that logs a message. Because handleLog is redefined inline on every render, React.memo sees a new function prop and re-renders Child. The fix is to declare handleLog with useCallback and an empty dependency array so the reference is stable and Child skips the re-render.

Interview question

Why does a React.memo child re-render when its parent passes an inline arrow function with identical code?

  • a.Because the inline function executes during every parent render and triggers a state update
  • b.Because React.memo ignores non-primitive props such as functions during comparison
  • c.Because React.memo compares props with deep equality and detects changes in the function body
  • d.Because the function is recreated as a new object on each parent render, failing the shallow prop comparisonCorrect
Why?

The correct answer is C because inline functions are recreated as new object references on every parent render, causing React.memo's shallow comparison to see a changed prop. Distractor A is tempting because beginners often assume React performs deep equality checks, but React.memo only does shallow comparison by default.

Just read this? Test yourself on what you have been reading.

Read the original → react.dev

You just looked this up. Could you explain it out loud?

That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on react — each one lists the topics its interview covers.

See open roles