采纳答案成功!
向帮助你的同学说点啥吧!感谢那些助人为乐的人
const rooterReducer = combineReducers({counter, logReducer}); 这里没有传递state,是怎么分别对应上的
其实就是用对象管理的,直接看 redux 源码
for
(let i = 0; i < finalReducerKeys.length; i++) {
const key = finalReducerKeys[i]
const reducer = finalReducers[key]
const previousStateForKey = state[key]
const nextStateForKey = reducer(previousStateForKey, action)
if
(
typeof
nextStateForKey ===
'undefined'
) {
const errorMessage = getUndefinedStateErrorMessage(key, action)
throw
new
Error(errorMessage)
}
nextState[key] = nextStateForKey
hasChanged = hasChanged || nextStateForKey !== previousStateForKey
dispatch执行 reducers 时,根据 reducers 的名字,传入不同的 state
export function logReducer (state={isAuth: false, user: 'Admain'}, action) 老师请这样写的时候,dispach 会自动识别 state的默认参数值对吧。
非常感谢!
登录后可查看更多问答,登录/注册
全网唯一的React 16+Redux+React Router4实战课程,学到手是你的真本领!
1.9k 10
1.4k 9
1.1k 8
1.3k 8
1.3k 7
购课补贴联系客服咨询优惠详情
慕课网APP您的移动学习伙伴
扫描二维码关注慕课网微信公众号