useState

A Hook that adds local state to a function component. Returns the current state and a function to update it.

Syntax

react
const [state, setState] = useState(initialValue)

Example

react
function Counter() {
  const [count, setCount] = useState(0);
  return (
    <button onClick={() => setCount(count + 1)}>
      Count: {count}
    </button>
  );
}