Run Function In React Js using Button

Run Function In React Js using Button

// Methods To run function with Button in React JS

export default function Counter() {
const [count,setCount] = useState(0);
function handleIncrement(){
  setCount(count +1);
}

return (
    <div>
      <p>{count}</p>
      <button onClick={ _=>{handleIncrement()}}>Increment</button>
      <button>Decrement</button>
    </div>
  );
}


//  Other Method

export default function Counter() {
  const [count, setCount] = useState(0);

  const handleIncrement = () => {
    setCount(count + 1);
  };

  return (
    <div>
      <p>{count}</p>
      <button onClick={ handleIncrement }>Increment</button>
      <button>Decrement</button>
    </div>
  );
}