How does useState work and why is setState asynchronous?
Answer
•useState returns a value and a setter.
•setState schedules an update and re-render.
•Updates can be batched.
•To depend on the previous value, use a function: setX(prev => ...).
•Do not rely on instant change after setState.
Was this answer helpful?