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

**Code:** `setState during render` · **Category:** React · **Seen on:** React

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

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/react/cannot-update-component-while-rendering-different)
