When a component is created this.state is defined. Then, after calling setState React somehow splits the old and new state into two objects. Using for example the hook shouldComponentUpdate we can diff these two states like so:
shouldComponentUpdate(nextProps, nextState) {
return (this.state.foo != nextState.foo);
}
I downloaded the React source from github and i found where these functions were called, but it quickly became too hard to keep track of what was going on. I never found where this split (or however they implemented this behavior) takes place. I did find that shallow comparisons was/could be used by React to diff the states, so i wonder if they simply clone the state object and then merge the updated values into one of them so that the two of them can be compared later. Is this correct? In such a case, how is nested structures handled? Or are they using a version of get/set and/or a version of Proxy API to catch the changes somehow?