rt2zz / redux-persist

persist and rehydrate a redux store
MIT License
12.94k stars 866 forks source link

persistCombineReducers loads incorrect data #549

Open inv2004 opened 6 years ago

inv2004 commented 6 years ago

Hello, I just decided to update to v5 and found strange behavior: v4 - everything is perfect. v5 - connected component receives state of another combined reducer. for example:

state = {a:1; b:'aaa'}
persistCombineReducers(config, {a, b})

Component connect((state) => {a:state.a})(Component)

and Component receives this.props.a which can be 1 or 'aaa'.

If I replace persistCombineReducers with combineReducers => then everything is ok.

more code:

const recommended = (state=null, action) =>
  action.type == 'SET_RECOMMENDED' ? action.payload: state

const categories = (state=[], action) =>
  action.type == "SET_CATEGORIES" ? action.payload : state

export default { recommended , categories }

---
class Cat extends Component {
  render() {
    console.log(this.props.categories)
    return (<Text>...</Text>);
  }
}

mapState = (state) => {
  categories: state.categories
}

export default connect(mapState)(Cat)

this.props.categories is null sometimes.

rt2zz commented 6 years ago

for one thing, persistCombineReducers needs to take two arguments persistCombineReducers(persistConfig, {a, b})

inv2004 commented 6 years ago

I just checked my change: const reducer = persistCombineReducers(config, reducers) So, I had two arguments for it.

updated initial issue.