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/max bounds, onChange callback.
  • Renders the current count and +/− buttons; clicking updates the value and fires onChange.

Constraints

  • Production expectations: no direct state mutation, functional setState updates, 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 …
LeaderboardSalaryAccount