Build a counter that adds and subtracts with two buttons. You practice local state with useState and onClick events.
- and + buttons, already styled.role="status" on the number and the button texts: the tests use them.0 and it is shown inside the element with role="status".+ button adds 1 to the value.- button subtracts 1 from the value, but the value never goes below 0.0.+ three times → you see 3.- once → you see 2.A number that changes with interaction is state: store it with useState.
Each button needs its own onClick that updates that state.
If the new value depends on the previous one, use the functional form of the setter: setX((x) => ...).
useState and local state.onClick events.The console is empty
Run your code with Ctrl+S
This console starts empty every time the preview loads. The browser's DevTools console keeps the messages with Preserve log.