Skip to content

Commit

Permalink
Merge pull request #95 from prakhar-pal/fix-getters-not-reactive
Browse files Browse the repository at this point in the history
bugfix: fix the issue where getters are not updated after state has been updated
  • Loading branch information
dennybiasiolli authored Mar 20, 2022
2 parents 5578722 + 55cd3f8 commit ba2c50a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/components/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ export default (
...this.mappedGetters,
};

if (this.mappedState) {
if (this.mappedState || this.mappedGetters) {
this.unsubscribeFn = this.store.subscribe((mutation, state) => {
let newState = {};
// update state from store state
const newMappedState = mapStateToPropsFn(state, this.props);
const newMappedState = mapStateToPropsFn && mapStateToPropsFn(state, this.props);
if (!shallowEqual(this.mappedState, newMappedState)) {
this.mappedState = newMappedState;
newState = { ...newState, ...this.mappedState };
}

// update state from store getters, if any
if (this.mappedGetters) {
const newMappedGetters = mapGetterToPropsFn(this.store.getters, this.props);
const newMappedGetters = mapGetterToPropsFn && mapGetterToPropsFn(this.store.getters, this.props);
if (!shallowEqual(this.mappedGetters, newMappedGetters)) {
this.mappedGetters = newMappedGetters;
newState = { ...newState, ...this.mappedGetters };
Expand Down

0 comments on commit ba2c50a

Please sign in to comment.