← React Intermediate Questions - Set 2 Q16

How does React’s `useState` hook work?

React Intermediate Questions - Set 2

Example

const [n, setN] = useState(0);
setN(n + 1);          // value captured at render time
setN(prev => prev + 1);  // always the latest value

What to notice

← Back to the question list