The useState Hook
useState gives a component memory. It returns the current value and a setter. Calling the setter schedules a re-render with the new value.
Example
import { useState } from 'react';
function Counter() {
const [count, setCount] = useState(0);
return <button onClick={() => setCount(count + 1)}>{count}</button>;
}Exercise
Create state.
const [n, setN] = (0)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.