To optimize the rendering of React components, we often use the PureRenderMixin
. The PureRenderMixin
mixin only re-renders the components when the props or the state changed according to the shallow equality. This suppose that:
- we use immutable objects (so that the shallow equality always implies the deep equality);
- we rarely create fresh but identical objects (so that the deep equality often implies the shallow equality).
In order to enforce this workflow, we propose some runtime checks to assert that the shallow equality is indeed equivalent to the deep equality over the props. This helped us to remove some useless re-renderings, and protects us against mutation bugs.