useState

useState is the React hook that adds local state to a component. It returns the current value and a function to modify it; calling that function triggers a new render. State is kept between renders and the update can receive a function when it depends on the previous value.

Example

const [n, setN] = useState(0);
<button onClick={() => setN(n + 1)}>{n}</button>

Related concepts

The whole glossary