← React Intermediate Questions - Set 9 Q86
How do you update the state of a functional component in React?
React Intermediate Questions - Set 9
Example
1
2
3
const [n, setN] = useState(0);
setN(n + 1);
// never: n = n + 1
What to notice
- Only the setter schedules a render; direct assignment is lost on the next render.
← Back to the question list