Fix guides · Cursor, v0, Claude Code, Lovable, Bolt ·

Fix React "Cannot update a component while rendering a different component"

Warning: Cannot update a component (`X`) while rendering a different component (`Y`).

The 'Cannot update a component while rendering a different component' warning fires when component Y calls setX() during its render, where X belongs to a different component. Unconditional own-state setState (e.g., useState(props.value) plus setX(props.value)) produces 'Too many re-renders', not this warning. Only updates to another component's state during render trigger this warning. The fix is to move the cross-component setState into an event handler or useEffect.

Free · 3 a day · no signup

Common causes – and how to tell which one you have

1. Component calls parent setter during render

How to tell: Y calls setX(...) during render, where X is state from a parent component or a different component. This is a cross-component update and triggers the warning.

Fix: Move the setX call into an event handler or useEffect. Do not call a parent's setter during render.

2. Props copied into state (not this warning)

How to tell: A component copies props into state and calls setState during render to sync. This pattern may cause re-renders but does not produce the cross-component warning.

Fix: Derive the value during render without unconditional setState, or use a key to reset state when the prop changes. Do not call a parent's setter during render.

3. Child updates parent state during its render

How to tell: A child calls a parent's callback (which calls a parent setter) while building its JSX, or inside a render-time computation.

Fix: Call that callback from an onClick, onChange, or useEffect in the child, not during render.

How to fix it

  1. Read the warning: it names the component being updated (X) and the component doing the updating (Y). Open Y.
  2. Search Y's render body for any call to a state setter that belongs to X, or any setState called unconditionally outside an event handler or useEffect.
  3. If you're copying props into state, stop: compute the value during render from the props, or use a key on the component to reset it when the prop changes.
  4. If a child calls a parent's setter during render (for example to report a selection), move that call into an onClick, onChange, or useEffect that runs after render.
  5. If the update is genuinely event-driven, make sure the handler is attached to an event (onClick, onSubmit) or runs in a useEffect after commit, and is not invoked while building the JSX.
  6. Reload with the console open and confirm the warning is gone. Also review the render path of the component to make sure no setState runs during render.

Using Lovable, Bolt or v0?

In v0, Lovable or Bolt, tell the AI: "React warns 'Cannot update a component (X) while rendering a different component (Y). Move the setState call out of the render path into an event handler or useEffect, or derive the value during render instead of storing it. Don't remove StrictMode to hide it. Then confirm the warning is gone."

Using Cursor, Claude Code or Windsurf?

Ask Cursor or Claude Code to locate the setState that runs during render, show the exact line, and move it into an event handler or useEffect with correct dependencies. Have it run the app with the console open and paste the output showing the warning is gone. Reject 'wrapped it in setTimeout' or 'removed StrictMode' as fixes.

The “fix” to avoid

This warning fires during React's render phase, not during hydration. There is no hydration-related fix for it. The correct fix is to move the setState into an event handler or useEffect, or derive the value during render.

Copy-paste fix prompt for your AI coding tool

Paste this into Cursor, Claude Code, Lovable or Bolt:

My React app warns: "Cannot update a component (X) while rendering a different component (Y)." Find where Y updates X's state during render. Check for: a state setter called at the top level of Y's body or inside JSX, props copied into state with an unconditional setState, or a child calling a parent's setter during its render. Move the update into an event handler or useEffect, or derive the value during render without setState. Do not silence it by removing StrictMode. Explain the exact line that caused it, then confirm the warning is gone in the browser console.
Your error looks a bit different? Paste your exact error and get a diagnosis tailored to your code — free.

Questions people ask

Why does this only appear in development?

React shows this warning only in development builds as a development-only check in React DOM. In production the check is skipped. Fix the cause instead of relying on production hiding it.

Does removing StrictMode fix it?

Removing StrictMode does not fix the warning. StrictMode double-invokes render, but the warning is about a cross-component setState during render, not about double-invocation. The warning fires without StrictMode too. Fix the cause instead of removing StrictMode.

Is this the same as 'Maximum update depth exceeded'?

Related but different. Maximum update depth is an infinite loop of updates. This warning is a single update triggered during someone else's render. A render-phase setState can escalate into an update loop if it keeps re-triggering.

Related errors

Get fixes like this every week