Joshua R.
Joshua R.

Reputation: 2302

How does connect decide when to have react re-render?

Woking in (marvelous) react-redux, we go to some trouble to ensure that our store objects are immutable. This guarantees that we can identify deep changes to store objects by doing simple reference comparisons. Our pure mapStateToProps function takes the full store object and performs some arbitrary (but consistent) transformation to produce a new props object- presumably whenever the store changes. Is connect doing a deep comparison of the output of mapStateToProps to decide when a react update is necessary? If so how is it benefiting from the store's immutability requirement (i.e. since mapStateToProps always returns a new object)?

Upvotes: 0

Views: 42

Answers (1)

Theogry
Theogry

Reputation: 306

In react-redux's connect you can set options to decide how mapStateToProps (and others) decides if the props has changed or not. The default setting is to use shallowEqual, which compares objects in first level only.

May you add more about the second question? I cannot quite understand it. Thanks!

Upvotes: 1

Related Questions