diff --git a/src/integrations/preact.js b/src/integrations/preact.js index 81c09e3..0b92a97 100644 --- a/src/integrations/preact.js +++ b/src/integrations/preact.js @@ -24,7 +24,7 @@ export function connect(mapStateToProps, actions) { const store = context.store; let state = mapStateToProps(store ? store.getState() : {}, props); const boundActions = actions ? mapActions(actions, store) : { store }; - let update = () => { + const update = () => { let mapped = mapStateToProps(store ? store.getState() : {}, props); for (let i in mapped) if (mapped[i]!==state[i]) { state = mapped; @@ -35,13 +35,11 @@ export function connect(mapStateToProps, actions) { return this.setState({}); } }; + store.subscribe(update); this.componentWillReceiveProps = p => { props = p; update(); }; - this.componentDidMount = () => { - store.subscribe(update); - }; this.componentWillUnmount = () => { store.unsubscribe(update); }; diff --git a/src/integrations/react.js b/src/integrations/react.js index 672b3db..064f997 100644 --- a/src/integrations/react.js +++ b/src/integrations/react.js @@ -39,13 +39,11 @@ export function connect(mapStateToProps, actions) { return this.forceUpdate(); } }; + store.subscribe(update); this.UNSAFE_componentWillReceiveProps = p => { props = p; update(); }; - this.componentDidMount = () => { - store.subscribe(update); - }; this.componentWillUnmount = () => { store.unsubscribe(update); };