React · Lesson 33 of 120
State Quiz
Test yourself.
Let's review state. Pause after each question, and answer before I do.
- State quiz
- Pause and think
- Then check
Question 1
Why doesn't a normal variable update the page? Because React doesn't know it changed. State tells React to render again.
Quick check
A normal variable won't update the page because:
Question 2
How do you add one to the count safely, several times in a row? With an updater function.
Quick check
Safest way to add one:
Question 3
How do you update an object in state? Copy it with spread, and set the new object.
Quick check
To change customer.city:
Question 4
Two siblings need the same state. Where should it live? In their closest common parent.
Quick check
Shared state belongs in:
Summary
Well done. Next, a new section on thinking in React.
Key takeaways- Updaters
- Copy, don't change
- Lift state up
Next up: Thinking in React — from design to components