【发布时间】:2017-11-20 16:01:54
【问题描述】:
这样的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 并将其传递给每个组件,这并不难编码,但它是否高效?
【问题讨论】:
-
那么解决了吗?我有同样的问题,但我无法从答案中理解。
标签: javascript redux redux-saga nextjs