5 hands-on exercises and 5 find-the-bug challenges for the useState Explained lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.
Hold a count in state and show its starting value.
Add one to the count each time the button is pressed.
Flip a boolean and show on or off.
Store a name in state and show a greeting when clicked.
Keep two counters that do not affect each other.
Reassigning an ordinary variable does not re-render anything.
Assigning to the state variable never tells React anything changed.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspaceCalling the setter during render instead of on click.
The toggle sets the same value every time.
useState returns the value first and the setter second.