Derived State Playground

A value you can work out: keep it in state + useEffect, or work it out during render? On the neighbourhood head’s board the cast is read from the real DOM, so…

Why it matters

"Copy props into state, then sync it with useEffect" is one of the most common React bugs: stale values, extra renders, missed deps, even an endless loop. Knowing "work it out during render, don’t store it" wipes out the whole class of bugs.

The key idea

If it can be worked out from other state or props, don’t store new state

Common mistakes

Try it in this playground