我使用redux的combineReducers()辅助函数来组合两个缩减器,如下所示:
const rootReducer = combineReducers({
user: userReducer,
accounts: accountsReducer
})
我知道每个reducer只能修改它分配给的商店的一部分," user"和"帐户"在这种情况下。
我如何修改"用户"从我的帐户减速机我的商店的一部分?
答案 0 :(得分:3)
你不能。
您可以在两个Reducer中收听相同的操作,或者如果您需要根据帐户更新来更新用户状态'状态,然后你可以使用Redux thunks - https://github.com/gaearon/redux-thunk
const action = () => (dispatch, getState) => {
// dispatch action that accounts reducer listens to
dispatch({
type: 'SOME_ACTION'
})
// get the new accounts state
let { accounts } = getState()
// dispatch action that user reducer listens to, passing the new accounts state
dispatch({
type: 'ANOTHER_ACTION',
payload: {
accounts
}
})
}
// call with
dispatch(action())