As the error says, you are calling sagaMiddleware.run
before the store is created. On the line above you create a function that eventually creates the store (once it's called in the react component), but that happens only after you try to run the middleware which is too late.
There are two solutions to this problem depending on your needs.
a) Either get rid of the factory and just create the store immediately.
const sagaMiddleware = createSagaMiddleware()
const store = reduxCreateStore( // notice the missing () =>
rootReducer,
applyMiddleware(sagaMiddleware),
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__() )
sagaMiddleware.run(sagas);
export default ({ element }) => ( <Provider store={store}>{element}</Provider> )
b) Move the middleware logic into the create store function
const createStore = () => {
const sagaMiddleware = createSagaMiddleware()
reduxCreateStore(
rootReducer,
applyMiddleware(sagaMiddleware),
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
)
sagaMiddleware.run(sagas);
return store;
}
export default ({ element }) => ( <Provider store={createStore()}>{element}</Provider> )
I would recommend the first one unless there is a particular reason why you need the factory instead.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…