Skip to content

Commit a64103c

Browse files
committed
Don't call setState in Provider if unmounting
1 parent 0374936 commit a64103c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/components/Provider.js

+13
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,25 @@ export function createProvider(storeKey = 'store') {
4040
this.subscribe();
4141
}
4242

43+
componentWillUnmount() {
44+
if(this.unsubscribe) {
45+
this.unsubscribe()
46+
this._isMounted = false;
47+
}
48+
}
49+
4350
subscribe() {
4451
const {store} = this.props;
4552

53+
this._isMounted = true;
54+
4655
this.unsubscribe = store.subscribe( () => {
4756
const newStoreState = store.getState();
4857

58+
if(!this._isMounted) {
59+
return;
60+
}
61+
4962
this.setState(providerState => {
5063
// If the value is the same, skip the unnecessary state update.
5164
if(providerState.storeState === newStoreState) {

0 commit comments

Comments
 (0)