ReactQuestion 12 of 28
What is state in React?
Answer out loud or in your head first, then compare.
Answer
State is a component's data that can change over time.
JavaScript
const [count, setCount] =
useState(0);Changing state schedules a re-render.
We don't mutate state directly.
Wrong:
JavaScript
user.name = "Tom";better:
JavaScript
setUser({
...user,
name: "Tom"
});How did it go? Be honest — “Not yet” puts the question on your review list.
Practise in code
- Counter from 0 to 20 — guided self-review