更新redux-persist白名单时不会保存状态

时间:2019-02-12 06:05:21

标签: react-native redux react-redux redux-persist

我通过添加另一个reducer更新了我的redux-persist白名单,即使更改了新的reducer,状态也不会保存。但是状态保存为先前的减速器。

  

我尝试通过刷新检查更新状态。(cmd + R-> ios)

    const persistConfig = {
      key: 'root',
      storage,
      whitelist: ['user'],
    };

    const persistedReducer = persistCombineReducers (persistConfig, reducers);

    const middlewares = [promiseMiddleware (), thunk];

    // eslint-disable-next-line
    if (__DEV__) {
      middlewares.push (createLogger ());
    }

    export default () => {
      const store = createStore (
        persistedReducer,
        undefined,
        compose (applyMiddleware (...middlewares))
      );
      const persistor = persistStore (store);
      return {store, persistor};
    };

在更新代码之前,用户的状态一直保持不变

    const persistConfig = {
      key: 'root',
      storage,
      whitelist: ['user', 'home'],
    };

    const persistedReducer = persistCombineReducers (persistConfig, reducers);

    const middlewares = [promiseMiddleware (), thunk];

    // eslint-disable-next-line
    if (__DEV__) {
      middlewares.push (createLogger ());
    }

    export default () => {
      const store = createStore (
        persistedReducer,
        undefined,
        compose (applyMiddleware (...middlewares))
      );
      const persistor = persistStore (store);
      return {store, persistor};
    };

在更新白名单之后,状态不会保存到家用减速器中。

0 个答案:

没有答案