在我开始组合我的 Redux 减速器之前,我的应用程序运行良好。但是当我组合时,initialState 和 reducer 键会混淆。
function flash(state = [], action) {
switch (action.type) {
case FLASH_MESSAGE_UPDATED:
return _.extend({}, state, { flash: action.flash })
default:
return state
}
}
function events(state = [], action) {
switch (action.type) {
case EVENTS_UPDATED:
return _.extend({}, state, { events: action.pathway_events })
default:
return state
}
}
export default combineReducers({
events,
flash
})
这会导致功能中断和控制台错误:
Unexpected keys "one", "two" found in initialState argument passed to createStore. Expected to find one of the known reducer keys instead: "events", "flash". Unexpected keys will be ignored.
我的初始状态是在 redux-thunk 的帮助下传入的。
import { createStore, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import reducer from '../../reducers/event'
let initialState = {
one: globalData.one,
two: globalData.two,
events: globalData.events,
flash: globalData.flash
}
let createStoreWithMiddleware = applyMiddleware(thunk)(createStore)
let reduxStore = createStoreWithMiddleware(reducer, initialState);
React.render(
<Provider store={reduxStore}>
<EventListContainer />
</Provider>,
$('.events')[0]
)
如何正确组合减速器?