Reputation: 33
Can react-redux still make use of shouldComponentUpdate if i'm using Immutable.js? The connect() method uses shallowEqual in shouldComponentUpdate() but from the Immutable.js docs i see that we have to use Immutable's own equals() method to check equality rather than the === operator (which shallowEqual uses)
Consider this:
const map1 = Immutable.Map({a:1, b:2, c:3});
const map2 = Immutable.Map({a:1, b:2, c:3});
map1 === map2 // returns false
map1.equals(map2) // returns true
Upvotes: 2
Views: 1052
Reputation: 8686
The whole point of using immutable.js
is to keep the reference when the underlying object actually don't change. The shallowEqual
performs a quick equality check between property, that's a huge gain over deep comparing value with immutable.equals
.
Example :
let state = Immutable.Map({a: 1, b:2, c:3)}
let state2 = state.set('a', 1)
state === state2 //true because Immutable returns the same reference object since there is no changes
In your example you explicitly allocate two different Immutable.Map
objects so it's two different object in memory and map1 === map2
returns false
.
Upvotes: 5