Full stack development

Stage 2 · Lesson 5 of 8

State, events and lifting state up

Git, npm and React

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

  • GuideFree
    React Documentation

    Meta

    Free official course; Thinking in React and Managing State matter most

  • CourseFree
    Full Stack Open

    University of Helsinki · Intermediate

    Free: Parts 0 to 2 cover web basics, React and talking to a server

Practise

Keep handy

Mark this stage as not done?