Lesson 16 of 3053%

(Progress persistence is disabled until Phase 9)

React
Beginner

Updating State

Triggering re-renders by updating state.

To change the state, you must call the setter function (setCount).

Never modify the state variable directly!

// WRONG! React won't trigger a re-render.
count = count + 1;

// CORRECT! React will update the state and re-render the UI.
setCount(count + 1);

Every time you call the state setter function, React automatically re-runs your component function, calculates the new JSX, and updates the DOM in the browser!

Try It Yourself

Lesson Progress

Take QuizBuild a React Project