Interactive Counter Component

Easy5 minutes

Build a functional counter component using React Hooks that allows users to increment and decrement a value.

Component Requirements

  • Use the useState hook to manage a count value
  • Display the current count in a paragraph with id value
  • Include two buttons: one with id increment and another with id decrement
  • Properly increase and decrease the count when the corresponding buttons are clicked

Implementation Notes

  • Start with the count initialized to 0
  • Use functional updates like setCount(prev => prev + 1) for best practice
  • Your component should be the default export

Example Code Structure

<div className="counter-app">
  <p id="value">0</p>
  <div className="button-group">
    <button id="increment">+</button>
    <button id="decrement">-</button>
  </div>
</div>
App.js
Loading...