Skip to content

Commit 129ad67

Browse files
committed
update hashFunction on state shape change
1 parent b018b98 commit 129ad67

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/components/Provider.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { Component } from 'react'
22
import PropTypes from 'prop-types'
33
import Context, { createHashFunction } from './Context'
4+
import shallowEqual from '../utils/shallowEqual'
45

56
const ContextProvider = Context.Provider
67

@@ -32,13 +33,21 @@ class Provider extends Component {
3233
}
3334

3435
componentDidUpdate(lastProps) {
35-
if (lastProps.store !== this.props.store) {
36+
const state = this.props.store.getState()
37+
const storesEqual = lastProps.store === this.props.store
38+
if (!storesEqual) {
3639
if (this.unsubscribe) this.unsubscribe()
3740
this.unsubscribe = this.props.store.subscribe(this.triggerUpdateOnStoreStateChange.bind(this))
38-
const state = this.props.store.getState()
3941
this.setState({
4042
state,
41-
store: this.props.store,
43+
store: this.props.store
44+
})
45+
}
46+
if(
47+
!storesEqual ||
48+
!shallowEqual(Object.keys(state), Object.keys(lastProps.store.getState()))
49+
) {
50+
this.setState({
4251
hashFunction: createHashFunction(state)
4352
})
4453
}

0 commit comments

Comments
 (0)