DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk6 min

React: Cannot Update a Component While Rendering a Different Component

The React warning means one component's state changed while another was rendering. Here is how to trace the call path and move the update to the right place.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The message means that while React was rendering one component, code caused a state update in a different component. React flags this because rendering should only calculate what the screen shows. The fix is to find the call that runs during render and move it to the place where the change actually originates: an event handler, or an Effect when there is a genuine side effect.

What the warning is telling you

The warning names two components. The first is the component that was rendering when the update happened. The second is the component that received the update. The first one is where you start looking, because the offending call sits somewhere in its render path or in code that path invokes.

React introduced this check in v16.13.0, released February 26, 2020. The release note, titled “Warnings for some updates during render,” states the principle directly:

“A React component should not cause side effects in other components during rendering.”

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The same note separates a case that React supports:

“It is supported to call setState during render, but only for the same component.”

So the warning is not about state updates during render in general. It concerns updates that cross from one component into another while React is still computing output.

Same-component and cross-component updates

Four situations come up when you trace a state change. They differ in whether React supports them and where they belong.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Situation Status in React Where the update belongs
A component calls its own setter while rendering Supported by the v16.13.0 release note, but must be guarded against repeating Render-time adjustment with a condition (see the render loop section)
A component calls a setter that belongs to a different component while rendering Produces the warning Move it out of render
A user changes an input or clicks a control Normal, expected behavior The matching event handler, such as onChange, onClick, or a submit callback
A genuine side effect must run after the screen updates Allowed useEffect, used only when no suitable event handler exists

How to find the update that triggers the warning

  1. Read both component names in the warning message. Note which one is the rendering component and which one is the update target.
  2. Open the stack trace attached to the warning and locate the frame inside the rendering component. The call that triggered the update appears in the stack above or below that frame.
  3. Search the rendering component, and any helper it calls during render, for setter functions. Look for setSomething calls, dispatch calls, form methods such as reset or setValue, navigation calls, and prop callbacks that write to a parent or sibling’s state.
  4. Check whether that call runs unconditionally on every render or only when some input changes. Either way, if it executes while the component body is running rather than inside a handler or Effect, it is the call to fix.

Common causes

A callback prop invoked in the component body

The most direct cause is a child that calls a parent-provided callback at the top level of its function body. The parent’s state changes while the child is still rendering. Here is the pattern to avoid:

function Child({ value, onValueChange }) {
  onValueChange(value.trim()); // runs during render: updates the parent mid-render
  return null;
}

A corrected version calls the callback in response to the user’s input, so the update happens inside an event handler:

function Child({ value, onValueChange }) {
  return (
    <input
      value={value}
      onChange={(e) => onValueChange(e.target.value.trim())}
    />
  );
}

Form library calls made during render

Form utilities can hide a setter call inside an ordinary-looking helper. In React Hook Form issue #9632, a user reported this warning. A maintainer identified reset and setValue calls made during render as the cause. The reporter said that moving their input formatting into onChange resolved their case. That is one reported case, not a general rule for every form setup or every version of the library.

Dispatches and store updates triggered while rendering

A dispatch to a reducer, a context setter, or an external store update can run during render if it sits in the component body or in a function that the body calls immediately. The stack trace will usually point to the helper. Move the dispatch into the handler that represents the user action, or into an Effect if it must run after the component commits.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Library code invoked during render

A third-party library can perform the update on your behalf when your component calls into it during render. The same method applies: trace the stack from the rendering component to the library call, then decide whether that call should move into a handler or Effect. If the library’s own code is the origin, check its issue tracker for similar reports before changing your code around it.

How to fix it

Where the update comes from Fix
A user typed, clicked, or submitted Move the update into onChange, onClick, or the submit callback
The value is derived from props or other state Calculate it during render instead of copying it into another component’s state
A genuine side effect must follow rendering, such as syncing with an external system Use useEffect, as described below
A form or other library method is called during render Move the call into the handler that represents the user action, and confirm the library’s recommended pattern in its documentation

Calculating derived values during render follows React’s guidance that rendering must stay pure: a component should return UI without changing pre-existing state or variables. Event handlers are the usual place for side effects triggered by user action.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When an Effect is the right tool

React’s “Keeping Components Pure” guidance describes Effects as a last resort, to be used when no suitable event handler exists. An Effect is appropriate for synchronizing with something outside React, such as a subscription, a network request, or a DOM API.

An Effect is not a place to shuffle ordinary derived data. Moving a calculation into useEffect only delays it and adds a render cycle. Do not reach for an Effect to silence the warning if the value could simply be computed during render or set in a handler.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The v16.13.0 release note also described an Effect as the option for the rare, intentional case of updating another component as a consequence of rendering. In practice, that case is uncommon, and it still requires the update to run after React has committed the render.

Same-component updates and render loops

Calling your own component’s setter during render is supported, but only when you guard it. Without a guard, the component renders, sets state, renders again, and can continue indefinitely. React’s useState reference lists “Too many re-renders” among its troubleshooting topics, and that message is the usual sign of a loop.

A guarded pattern compares the current input with a value stored from a previous render, and updates state only when the two differ:

function Counter({ items }) {
  const [count, setCount] = useState(0);
  const [prevItems, setPrevItems] = useState(items);

  if (items !== prevItems) {
    setPrevItems(items);
    setCount(0);
  }

  return count;
}

The guard stops the cycle because the second render sees matching values and makes no further updates. Without the comparison, the same code would loop.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Do not suppress the warning

Silencing the console message leaves the cross-component update in place. The state change still runs during render, and the behavior the warning flags remains. Fix the call path first; the warning should then stop appearing without any suppression.

Version notes

The behavior described here is the one React introduced in v16.13.0 on February 26, 2020. The current React documentation expresses the same principle in terms of render purity rather than in the release-note wording. If you run a different React version, confirm the exact warning text and any version-specific behavior against that version’s documentation before relying on a specific message.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.