Question · JavaScript and React course · Module 3: State and Events
Functional setState Update
Why should you use functional updates (prev => prev + 1) when calling setState multiple times in a single handler?
Answer options
- Because React requires it syntactically - a direct value causes an error
- Because React batches updates and each call with a direct value sees the same stale state
- Because functional updates are faster than passing a value directly
- Because without functional updates React does not store state in memory
You can check the correct answer by solving this task in the CodeWorlds game.