像这样的js
import {createStore, applyMiddleware, combineReducers} from 'redux'
import {composeWithDevTools} from 'redux-devtools-extension'
import withRedux from 'next-redux-wrapper'
import nextReduxSaga from 'next-redux-saga'
import createSagaMiddleware from 'redux-saga'
import {initialState} from './initialState'
import globalSaga from '../sagas/global'
const sagaMiddleware = createSagaMiddleware()
export function configureStore (reducers,initialState) {
console.log(initialState)
let states = {}
Object.keys(reducers).map((key) => {
states[key] = initialState[key]
})
console.log(reducers)
console.log(states)
const store = createStore(
combineReducers({reducers}),
states,
composeWithDevTools(applyMiddleware(sagaMiddleware))
)
store.sagaTask = sagaMiddleware.run(globalSaga)
return store
}
export function withReduxSaga (BaseComponent, reducers) {
return withRedux(configureStore(reducers,initialState))(nextReduxSaga(BaseComponent))
}
export default function configureWithReduxSaga(component,reducers){
return withReduxSaga(component,reducers)
}
错误是
Store does not have a valid reducer. Make sure the argument passed to
makeStore is not a function
可能有什么问题,基本上我想编写一个函数,将具有特定 sagas 的reducers和store.global添加到 nextjs 组件中,而不需要太多代码,最好是这样的:
configureWithReduxSaga(
{reducer1, reducer2},
{saga1, saga2}
)
可能吗?我可以创建 root reducer 和 root saga 并将其传递给每个组件,这并不难编码,但它是否高效?