Stage 2 · Lesson 4 of 8
State, events and lifting state up
State is data that changes over time and should update the screen. You hold it with 's . Calling the setter asks React to draw the component again with the new value.
It does not change the variable in the current render, which is why logging right after setCount still shows the old value. Never change an object or array in state directly. Create a new one with (...), map or filter instead.
When two components need the same data, move the state up to their closest shared parent. Pass the value down, plus a function that changes it. This is called .
Work out values instead of storing them: a filtered list made from the items and a search term needs no state of its own. Most React bugs come from state in the wrong place, or the same data stored twice.
A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock
Resources for this stage
Start with· follow one of these
- GuideFreeReact Documentation
Meta
Free official course; Thinking in React and Managing State matter most
- CourseFreeNext.js Learn
Vercel · Intermediate
Free official course: the first chapters build pages, layouts and navigation