5
ReduxとRedux-Thunkを使用して作成されたReactアプリがあります。 Redux docsごとに減速材を組み合わせようとするまで、すべてうまくいく。最初の、機能的な減速React-Redux:還元剤の組み合わせが失敗する
export default function bigReducer(state = { events: [], flash: [] }, action) {
switch (action.type) {
case EVENTS_UPDATED:
return _.extend({}, state, { events: action.pathway_events })
case FLASH_MESSAGE_UPDATED:
return _.extend({}, state, { flash: action.flash })
default:
return state
}
}
を私は複合減速に
function flashReducer(state = { flash: [] }, action) {
switch (action.type) {
case FLASH_MESSAGE_UPDATED:
return _.extend({}, state, { flash: action.flash })
default:
return state
}
}
function eventReducer(state = { events: [] }, action) {
switch (action.type) {
case EVENTS_UPDATED:
return _.extend({}, state, { events: action.pathway_events })
default:
return state
}
}
// either with simple reducer composition
export default function bigReducer(state = {}, action) {
return {
flashReducer: flashReducer(state.flash, action),
eventReducer: eventReducer(state.events, action)
}
}
// or with the combineReducers function
export default const reducer = combineReducers({
flashReducer,
eventReducer
})
初期状態を作成しようと減速が
を混入しているように見えるが与えられ
// logging the state var EventListContainer = connect((state) => { console.log(state) return { events: state.events })(React.createClass({ ... // returns the incorrect state # => Object {flashReducer: Array[0], eventReducer: Array[17]}
ReactorとReduxを使用して減速機を組み合わせるにはどうすればよいですか?
私の更新を見てください。あなたはsateキーに従ってレデューサー関数の名前を付ける必要はありませんが、 'combineReducers'を使うとレデューサーキーを状態キーに揃える必要があります。 – nrabinowitz
混乱してごめんなさい、最初に最小回答を投稿し、拡張回答を更新として投稿するという習慣を持つようにしてください。 – nrabinowitz
ユーレカ、そうした。どのように私がそれを逃したかわからない、それは重要です。ありがとうございました。 – steel