call(back)

Build a Counter

Build a counter component. The buttons are already on screen — make them work.

Requirements

  • +1 and -1 change the displayed count.
  • The count never goes below zero: -1 is disabled at 0.
  • Reset returns the count to 0.

Talk through where the state lives and why the disabled state should be derived from it rather than stored separately.

Hints

Hint 1

One useState(0) is the only state this needs — everything else on screen is derived from it.

Hint 2

Disable with disabled={count === 0} instead of tracking a second boolean; two sources of truth drift.

Asked at