Back to all tasks

Implement a Controlled Counter Component with useState

Your task is to complete and debug a React functional component Counter. This component should display a numerical value and provide two buttons: "Increment" and "Decrement".

Requirements:

  1. The counter value should be initialized to 0.
  2. Clicking "Increment" should increase the counter by 1.
  3. Clicking "Decrement" should decrease the counter by 1.
  4. The component must correctly manage its internal state using React hooks.
  5. Ensure all state updates are performed correctly and predictably, triggering re-renders as expected.
implement_a_controlled_counter_component_with_usestate.jsx
Loading...

Use the "Verify Solution" button to get AI feedback on your React code.