It’s fairly simple. This function is passed 2 arguments: the next state, and the previous state. You return a boolean telling whether the two states have changed, regarding the state slice you’re interested in, and if the function returns true, mapStateToProps will not even be called.

Let’s update our example to use this function :

Now, when state.users.all changes, the TodoContainer’s areStatesEqual option will be called, it will return true, and thus it’s mapStateToProps function won’t even be called.

If you have a more complex selector, simply compare each part of the state used in mapStateToProps:

Most of the times it is enough and I rarely use memoization.

These examples don’t have complex computation of props, so in these cases performance wouldn’t be impacted so much since by default connected components are pure. They’re just examples. It makes much more sense when using more complex mapStateToProps.

Memoization remains useful when using props in mapStateToProps and methods that return new objects or arrays.