React Increment/Decrement Counter Component
Problem Build a React counter component that displays a value with buttons to increment and decrement it. Provide production-quality implementations both as a class component and as a functional component with hooks.
Input / Output
- Props: optional
initialValue,step,min/maxbounds,onChangecallback. - Renders the current count and +/− buttons; clicking updates the value and fires
onChange.
Constraints
- Production expectations: no direct state mutation, functional
setStateupdates, accessible buttons (aria-labels), and disabled buttons at the min/max bounds.
Example
<Counter initialValue={0} step={1} min={0} />→ clicking + three times shows 3; − at 0 stays 0 (button disabled).
asked …