Hello World Counter
UI Coding
Easy
10 min
state
events
accessibility
Build the "hello world" of React: a counter.
The starter renders the markup but nothing is wired up yet.
Requirements
- The count starts at 0 and is displayed in a large number.
- Increment adds 1 and Decrement subtracts 1.
- The count can never go below 0. The Decrement button is disabled while the count is 0.
- Reset sets the count back to 0. It's disabled when the count is already 0.
- Screen-reader users should hear the new value after each change, without the focus moving. Put the number in an element with
role="status". - Each button has a clear accessible name: "Increment", "Decrement", "Reset". If you use symbols such as
+and−as the visible text, add anaria-label.
Follow-up
- Add a "step" input so each click adds or subtracts N.
- Why does calling
setCount(count + 1)three times in one handler only add 1? How do you fix it? - How would you make this a reusable
useCounter({ min, max, step })hook?
Spotted a mistake or a rights concern? Report an issue