March 2019
Intermediate to advanced
350 pages
7h 28m
English
As we have seen, the most powerful tool we can use to improve the performance of our React application is shouldComponentUpdate using PureComponent.
The only problem is that PureComponent uses a shallow comparison method against the props and state, which means that if we pass an object as a prop and we mutate one of its values, we do not get the expected behavior.
In fact, a shallow comparison cannot find mutation on the properties and the components never get re-rendered, except when the object itself changes.
One way to solve this issue is using immutable data: Data that, once it gets created, cannot be mutated.
For example, we can set the state in the following mode:
const obj = this.state.obj; obj.foo = 'bar'; this.setState ...
Read now
Unlock full access