Skip to content
Justice Tech School

useState

useState returns the value and a setter. Calling the setter re-renders.

Example
import { useState } from "react";
function Counter() {
  const [n, setN] = useState(0);
  return <button onClick={() => setN(n + 1)}>Clicked {n}</button>;
}

Exercise

Setter call.

(n + 1)

Quiz Test

What does the setter trigger?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.