React & Next.js errors · Error 04 of 7
“Cannot update a component while rendering a different component”
By Muhammad Abdullah, full-stack, mobile and ai automation developer · Last reviewed
Cannot update a component (`X`) while rendering a different component (`Y`)Short answer
A child component calls a parent’s state setter during its render. Move that call into an event handler or a useEffect.
Common causes
- Calling a callback prop like
onChange(value)directly in the child’s body. - Updating a global store (context, Zustand, Redux) during render.
How to fix it
Notify the parent after render instead:
useEffect(() => { onChange(value); }, [value, onChange]);Better still, lift the state up so the parent computes it and no sync is needed.