1 回答

TA貢獻(xiàn)1834條經(jīng)驗(yàn) 獲得超8個(gè)贊
更好的方式是合并成一個(gè)dispatch:
const data = (user, article, comment) => ({type: 'INIT_BLOG', data: {user, article, comment}})
dispatch 這個(gè)Action
reducer:
const blogReducer = (state = {}, action) => {
switch (action.type) {
case 'INIT_BLOG':
return {...state,
comment: action.data.comment,
article: action.data.article,
user: action.data.user
};
case 'ADD_COMMENT':
return {...state, comment: [...state, action.data.comment]};
default:
state;
}
}
你上面的寫法功能是可以的,但不符合reducer的習(xí)慣寫法
添加回答
舉報(bào)