setState during render ⚛️ React

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.

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 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.