Skip to main content
DevTyp.i.ng
Back

Share

How to use ''useState" in Reactreact

00:00:00

Press Esc to exit this exercise.

import { useState } from "react";

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

  function handleClick() {
  setCount(count => count + 1);
  }

  return (
  <>
    <h1>{count} times</h1>
    <button onClick={handleClick}>Add 1</button>
  </>
  );
}