liveBook · Manning

Component re-rendering

As explained in React in Depth

Component re-rendering is the process of rendering a React component again after its relevant inputs or state change.

Component re-rendering is React’s process of executing a component again to produce updated output. A changed prop is neither necessary nor sufficient: a child re-renders when its parent renders, even with unchanged props, while mutating a ref can change a prop value without triggering a render. section 3.1.1

Use these distinctions when diagnosing render behavior and performance:

  • State updates can trigger a parent render and therefore re-render its children, regardless of the children’s props. section 3.1.1
  • A ref mutation does not itself schedule a render, so a changed value may not appear in the child’s output. section 3.1.1
  • Minimize unnecessary renders when rendering threatens frame time or interface responsiveness; memoization is one available optimization. section 3.2
  • Manual memoization remains relevant while the React Compiler is experimental and not widely adopted. section 3.2

Testing the prop-change myth

Render one child beneath a parent whose state update changes nothing passed to that child, then render another child whose prop reads from a mutated ref. The first child re-renders when its parent updates; the second does not re-render when only the ref changes. A visible first-render indicator makes the difference observable. section 3.1.1

Listing 3.1 A component that highlights re-renders
import { useEffect } from "react";
import { useRef } from "react";
export function Rerenderable() {
  const isFirst = useRef(true);
  useEffect(() => {
    isFirst.current = false;    #1
  }, []);
  const style = #2
    { color: isFirst.current ? "red" : "blue" };    #2
  const text = isFirst.current  #2
    ? "First render" : "Not first render";    #2
  return <p style={style}>{text}</p>;
}

Inspect a small diagnostic component that uses a ref and effect to distinguish its first render from later renders. section 3.1.1

How React in Depth covers it

How deep it goes
Demonstrates render triggers with runnable components and connects them to frame budgets and memoization.
Examples
Uses visible render instrumentation, contrasting buttons, a state update, and a ref mutation.
What you can do after
Diagnose unexpected renders and choose whether to reduce state updates or apply memoization.
How it connects
Connects parent rendering, props, state updates, refs, memoization, and the React Compiler.

Also explained in

Compare how 3 books explain component re-rendering →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of React in Depth. The section links point to the parts of the book it draws on.