Why does a React Component Re-render? Causes and Fixes

Understand what triggers React renders, why a render may not change the DOM, and how to diagnose avoidable rendering work before using memoization.

Why does a React Component Re-render? Causes and Fixes

Why does a React Component Re-render?

In React, rendering means React calls a component to figure out what its next UI should look like. A re-render does not automatically mean React rewrites the DOM. React compares the new output with the previous one, then commits only the DOM changes that are necessary. If the output is effectively the same, the DOM may not need an update at all. React: Render and Commit

What can trigger a render?

After the initial render, the most common reasons include:

  1. The component's state is updated. Calling a useState setter queues an update. If the next state is the same value as the current one according to Object.is, React can skip rendering that component's children.
  2. A parent renders again. By default, React calls the components nested below that parent as it renders the tree again. A child's own props do not have to be different for this to happen.
  3. A context value it reads changes. React updates components that consume that context when the provider receives a different value.

New props often arrive because the parent rendered and passed them down. A component wrapped in memo may skip a parent-triggered render when its props compare equal, but its own state or a context it reads can still trigger a render. React: memo · React: useContext

A parent render can call its children again

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

  return (
    <>
      <button onClick={() => setCount((value) => value + 1)}>
        Parent count: {count}
      </button>
      <Child label="Stable label" />
    </>
  );
}

function Child({ label }) {
  console.log("Child rendered");
  return <p>{label}</p>;
}

Clicking the parent button updates Parent's state. React renders Parent again and, by default, calls Child as part of rendering the nested tree—even though label is still the same string. That is a render; it does not necessarily mean the paragraph's DOM node is changed.

When do new object and function references matter?

JavaScript creates a new object or function when its literal or function expression runs again. This matters when passing values to a memoized child, because memo compares props by reference for objects and functions:

const Results = memo(function Results({ options, onSelect }) {
  console.log("Results rendered");
  return <button onClick={onSelect}>{options.sortBy}</button>;
});

function SearchPage() {
  const [query, setQuery] = useState("");
  const options = { sortBy: "name" };
  const onSelect = () => console.log("Selected");

  return (
    <>
      <input value={query} onChange={(event) => setQuery(event.target.value)} />
      <Results options={options} onSelect={onSelect} />
    </>
  );
}

Each time SearchPage renders, it creates a new options object and a new onSelect function. They have new references, so the memoized Results sees changed props and renders again. This is not automatically a problem: first confirm the repeated work is noticeable and that skipping it would help.

If profiling shows it matters, stabilize only the values that need it:

const options = useMemo(() => ({ sortBy: "name" }), []);
const onSelect = useCallback(() => console.log("Selected"), []);

Now, while the dependencies remain the same, React can reuse those references so memo has a chance to skip rendering Results. useMemo and useCallback are performance tools, not requirements for every object or function. One changing prop is enough for memo to render the child. React: useMemo · React: useCallback

Other avoidable update patterns

  • State kept too high in the tree. If typing in one form field updates a page-level component, many descendants may render again. Keep short-lived state near the component that uses it unless other components need it.
  • An effect that copies derived data into state. If a value can be calculated from current props or state during render, storing a duplicate and updating it in an effect can add an extra render. Calculate it directly when practical.
  • A context provider creates a new value on every render. Consumers see a changed context value by identity. If profiling shows this is costly, consider splitting context by responsibility or stabilizing the provider value where appropriate.

Find the cause before optimizing

Use React Developer Tools to inspect which components render during an interaction, and use the Profiler to identify work that actually costs time. Then check whether a render is expected, whether the component does expensive work, and whether its UI output changes. Fix the source first—such as moving local state down or removing an unnecessary effect. Add memo, useMemo, or useCallback only when they address a measured bottleneck. React: memo · React: Profiler

Try it yourself

Add a child component that logs when it renders. Update state in its parent and observe what happens. Then wrap the child in memo and pass it a string prop. Finally, pass it an object literal, observe the new reference, and use the Profiler to see whether avoiding that work makes a meaningful difference.

Recap

  • State updates, parent renders, and changed context values can cause components to render again.
  • A render is React calculating UI; the DOM is only committed where changes are needed.
  • Parents normally render their descendants again; memo can skip some parent-driven renders when props are unchanged.
  • New object and function references matter when a memoized child compares those props.
  • Profile first, fix unnecessary update patterns, and memoize selectively.

What's next?

Next, we’ll look more closely at how state works in React.

Written by

Dev Likhon

Dev Likhon

Full Stack Developer & Tech Educator

6+ years of professional development experience.

About Me
Share:

Comments

Share what you learned or ask a question.

Loading comments...