Я вызываю Redux функцию действия из хранилища, но отображается ошибка store.dispatch" TypeError: __WEBPACK_IMPORTED_MODULE_6__store__. A.dispatch не является функцией ".
Код магазина приложений:
import store from './store';
if (localStorage.getItem("persist:root")) {
const persistData = localStorage.getItem("persist:root")
const root = JSON.parse(persistData)
const field = JSON.parse(root.auth)
const expiresIn = field['authToken']["expiresIn"]
//check expire date
const currentTime = Date.now() / 1000;
if(expiresIn<currentTime){
store.dispatch(logoutUser());
window.location.href='/login';
}
}
Действие Redux:
export const logoutUser = ()=>dispatch=>{
//......
dispatch(setCurrentUser({}));
}
Создать магазин:
const initialState = {};
const middleware = [reduxThunk];
const persistConfig = {
key: 'root',
storage,
whitelist: ['auth'],
blacklist: ['errors', 'profile', 'target']
};
const persistedReducer = persistReducer(persistConfig, rootReducer)
export default () => {
let store = createStore(
persistedReducer,
initialState,
composeWithDevTools(
applyMiddleware(...middleware),
)
);
let persistor = persistStore(store);
return { store, persistor };
};
Index.js:
import { Provider } from 'react-redux';
import configureStore from './store';
import { PersistGate } from 'redux-persist/integration/react';
const { persistor, store } = configureStore();
ReactDom.render(
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<App />
</PersistGate>
</Provider>
, document.querySelector('#root')
);