我得到这个错误store.getState is not a function
当我尝试为我的reactjs项目设置redux存储时 这是我的商店代码:
import { persistStore, persistReducer } from 'redux-persist';
import createSagaMiddleware from 'redux-saga';
import rootSaga from './sagas';
const sagaMiddlewares = createSagaMiddleware();
const middlewares = [sagaMiddlewares];
export default () => new Promise((resolve) => {
const enhancer = [applyMiddleware(...middlewares)];
window.devToolsExtension && enhancer.push(window.devToolsExtension());
const store = createStore(
persistReducer,
undefined,
compose(...enhancer)
);
sagaMiddlewares.run(rootSaga);
store.subscribe(() => console.log('redux store: ', store.getState()));
persistStore(store, null, () => {
resolve(store);
});
});
我的index.js:
...
import registerServiceWorker from './registerServiceWorker';
import { Provider } from 'react-redux';
import store from './store';
const app = (
<Provider store={store}>
<BrowserRouter>
<App />
</BrowserRouter>
</Provider>
);
ReactDOM.render(app, document.getElementById('root'));
registerServiceWorker();
如果我通过设置persistStore删除了商店中的Promise,它会运行,但是刷新商店时该商店为空 在我的减速器中: 我使用来自'redux-persist / lib / storage'的存储;并设置我的配置:
const config = {
key: 'root',
timeout: 30000,
storage: storage,
whitelist: ['token', 'me'],
blacklist: ['form']
};