What happens when you call setState (or a state setter) in React?
Model answer
The setter schedules a re-render. React calls your component function again with the new state, builds a new description of the UI, and updates the DOM where it changed. State updates may be batched, so several updates in one event usually cause one render.
The state variable does not change immediately inside the same render, so reading it right after calling the setter gives the old value.
Learn this topic
What Is React? Why Use It and How It Works in the course React.js Full Course: Beginner to Advanced.
Sign in to add your own answer.