Question
What happens when you call setState?
Answer
When the setState is called, first of all, it merges the object passed to it into current state of the component. This kicks off a process called reconciliation. The purpose of the process is to update the UI based on this new state. To achieve this, React constructs a new tree of React elements (that can be thought of as the object representation of UI) Once it has this tree, in order to figure out how the UI should change in response to the new state, React takes diff of new tree against the previous element tree. By doing this, React then knows the exact changes which occurred, and by knowing exactly what changes occurred, ables to minimize its footprint on the UI by only making updates where absolutely necessary.