Redux-Persist 不会在页面重新加载时保持我的状态

时间:2021-06-05 10:31:14

标签: reactjs redux react-redux

我有一个应用程序,我想保留我的数据,但由于某种原因它没有保留我的状态。

store.js

import { createStore, applyMiddleware } from "redux";
import { composeWithDevTools } from "redux-devtools-extension";
import thunk from "redux-thunk";
import rootReducer from "./reducers";

import { persistStore } from "redux-persist";

const middleWare = [thunk];

export const store = createStore(
  rootReducer,
  composeWithDevTools(applyMiddleware(...middleWare))
);

export const persistor = persistStore(store);

reducer.js

import { combineReducers } from "redux";
import { persistReducer } from "redux-persist";
import storage from "redux-persist/lib/storage";

import auth from "./auth";
import profile from "./profile";

//it tried with whitelist option too, but not working
const persistConfig = { key: "root", storage };

const rootReducer = combineReducers({ auth, profile });

export default persistReducer(persistConfig, rootReducer);

index.js

ReactDOM.render(
  <React.StrictMode>
    <Provider store={store}>
      <PersistGate persistor={persistor}>
        <App />
      </PersistGate>
    </Provider>
  </React.StrictMode>,
  document.getElementById("root")
);

我在我的其他应用程序中使用了相同的代码,它运行良好,但在我当前的应用程序中,它没有保存我的状态。

0 个答案:

没有答案