setState during render React Origin: On your device OSI layer 7 · Application Last updated 12 Oct 2026

Warning: Cannot update a component (`Parent`) while rendering a different component (`Child`)

A child component updated a parent’s state during its render instead of in an effect or event handler.

Exact message you may see Cannot update a componentwhile rendering a different component
Seen on: React

Meaning

Calling a parent’s setState (or a context/store setter) in the body of a child render causes this warning and can cause loops.

Common causes

  • Calling onChange/setState props directly in render
  • Store/context updates in render
  • Syncing derived state during render

⚡ Quick fix

  1. Move the update into useEffect or an event handler
  2. Derive values instead of syncing state

Detailed fix by platform

React

  1. useEffect(() => { onLoaded(items.length); }, [items.length, onLoaded]);

How to diagnose

  1. Components — Which parent/child are named?
  2. Call — Where is the setter called?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: On your device. Errors that are often confused with or caused by this one (click to open):

Actions must be plain objects — Error: Actions must be plain objects. Instead, the actual type was: 'function'. (React)Actions must be plain…Could not Fast Refresh — [vite] hmr invalidate … Could not Fast Refresh. Export is incompatible. (React)Could not Fast RefreshDynamic server usage — Error: Dynamic server usage: Route /x couldn't be rendered statically because it used `cookies` (React)Dynamic server usageElement type is invalid — Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined (React)Element type is inval…Error acquiring the state lock — Terraform: Error: Error acquiring the state lock — ConditionalCheckFailedException / state blob is already locked (Terraform)Error acquiring the s…Functions not valid as child — Warning: Functions are not valid as a React child. This may happen if you return a Component instead of <Component /> from render. (React)Functions not valid a…IllegalStateException — java.lang.IllegalStateException (Java)IllegalStateExceptionkey is not a prop — Warning: `key` is not a prop. Trying to access it will result in `undefined` being returned. (React)key is not a propsetState …

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.