React Dojo

Search

Search concepts, exercises and quizzes

practicebasic

Classic counter

A counter with controls to increment, decrement, and reset. The '+3' button must add three units even if pressed several times in a row — use functional updates.


Objectives

  1. 1.Declare a count state that starts at 0
  2. 2.+ button adds 1, button subtracts 1
  3. 3.reset button returns to 0
  4. 4.+3 button adds 3 using setCount(c => c + 1) three times
  5. 5.The display must show the current value centered
your code
Hint

Passing a function to setCount gives you the most recent value; passing a number uses the value captured in the render.

Related concepts

Was this helpful?
Sign in to give feedback