Sat. Apr 4th, 2026
import React, { useState } from "react";

function Counter() {
  // Step 1: Declare state
  const [count, setCount] = useState(0);

  // Step 2: Event handler to update state
  const increment = () => {
    setCount(count + 1);
  };

  const decrement = () => {
    setCount(count - 1);
  };

  return (
    <div>
      <h2>Counter: {count}</h2>
      <button onClick={increment}>+</button>
      <button onClick={decrement}>-</button>
    </div>
  );
}

export default Counter;

This will give you  a simple counter if you use it well….

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *