5 min read
0%

Bailout Conditions in Rendering

Back to Blog
Bailout Conditions in Rendering

Bailout Conditions in Rendering

React has several mechanisms to skip re-rendering when output won’t change. Understanding these “bailout” conditions helps you write more efficient components.

useState Same-Value Bailout

If you set state to the same value as current state, React skips re-rendering:

const [count, setCount] = useState(0);

setCount(0);     // same value — bailout
setCount(count); // same reference — bailout
setCount(prev => prev); // same value returned — bailout

React uses Object.is for comparison. New object references are never equal:

setUser({ name: 'Alice' }); // new object reference — always triggers re-render

React.memo

const Child = React.memo(function Child({ value }) {
  return <div>{value}</div>;
});

React.memo does shallow prop comparison using Object.is. If all props are the same reference, the component doesn’t re-render.

Bailout fails when:

  • Props include inline objects: <Child config={{ a: 1 }} /> — new object every render
  • Props include inline functions: <Child onClick={() => {}} /> — new function every render
  • Any prop changes — even to a value that looks the same

PureComponent (Class Components)

React.PureComponent implements shouldComponentUpdate with shallow prop and state comparison — the class equivalent of React.memo.

shouldComponentUpdate

Full manual control:

class Chart extends React.Component {
  shouldComponentUpdate(nextProps) {
    return nextProps.data !== this.props.data;
  }
}

Return false to bail out.

useMemo and useCallback

Preserve referential identity so React.memo can bail out:

const config = useMemo(() => ({ color: 'blue' }), []);
const handler = useCallback(() => doSomething(), []);

<MemoizedChild config={config} onClick={handler} />

Context Bailout

When context value changes, all consumers re-render. The only bailouts:

  1. The value reference didn’t change (memoize the context value object)
  2. The component doesn’t subscribe to that context

Fiber Reconciliation Bailout

React may skip a subtree entirely if:

  • A parent bailed out via React.memo before reaching the child
  • A conditional branch wasn’t entered (condition && <Component /> where condition is false)

What Bailout Doesn’t Mean

Bailout skips the render function call. It doesn’t skip fiber traversal — React still walks the tree to decide whether to bail out. React.memo on a subtree root saves both the render call and the child traversal.


Canvas is not supported in your browser