Full answer
React tries to avoid work at several levels.
-
State bailout. When
setCount(value)is called with the same value as the current state (compared withObject.is), React may skip the update. There is an eager path: if the component has no pending updates, React calculates the next state immediately when you call the setter, sees it is equal, and does not schedule a render at all. When the component already has pending work or the eager check cannot be used, React schedules a render, calls your component function, finds that the state is unchanged, and bails out: it discards the result, does not render children, and does not run effects. That is the case when you may see one extra log from the component body, and it is not a bug. -
Identity bailout for elements. If an element object is identical to the previous one (same type, same props object), React skips the subtree. This is what happens for
childrenpassed through from a parent that did not re-render. -
memo. React compares props withObject.isper prop (shallow equality) and skips rendering the component if all are equal and its own state and context did not change. -
Context and selectors bail out by comparing the new value with the old one. Unchanged
useMemoanduseCallbackresults keep identities that make the other bailouts work.
Practical consequences: do not rely on the number of component function calls to infer commits. Side effects in the body will show these extra calls (another reason for purity). Mutating state and setting the same reference is a bailout, so the UI does not update. For objects, always create a new one when something changed.
The example logs renders in a parent and child while setting the same value repeatedly.
import { memo, useState } from 'react';
const Child = memo(function Child() {
console.log(' Child rendered');
return <p>child</p>;
});
export default function Parent() {
const [count, setCount] = useState(0);
console.log('Parent body called, count=' + count);
return (
<div>
<button onClick={() => setCount(1)}>Set to 1</button>
<button onClick={() => setCount(count + 0)}>Set to the same value</button>
<Child />
</div>
);
}The check pressed Set to 1 first, and then Set to the same value. The first press logged one Parent call and no Child render, because memo skipped the unchanged child. The second press, with the same value, logged one more Parent call with count=1 and no Child render. That extra call is the bailout check. Output of the run: Parent body called, count=0 Child rendered Parent body called, count=1 Parent body called, count=1
Key points
- Setting state to an identical value (Object.is) lets React skip the update.
- React may call the component one extra time before bailing out, without rendering children or running effects.
- Identical elements and memo with equal props skip subtrees.
- Do not infer commits from component function calls, and keep render pure.
- Mutating state and setting the same reference is a bailout, so the UI will not change.
Common mistakes
- Counting component function calls as proof of commits.
- Mutating a state object and calling the setter with the same reference.
- Putting side effects in the body and being surprised by extra calls.
- Expecting a same-value update to run effects.
- Assuming memo skips the component's own state updates.
Follow-ups
- What is the eager state computation, and when does it not apply?
- How does React decide that an element subtree can be skipped?
- What does the React Compiler change about these checks?
Tips
- List the bailout levels: state, element identity, memo, context.
- Explain the extra call as a check, not a commit.
- Tie it back to render purity.