我现在用的这种写法
export function getUserList(params) {
return (dispatch) => {
dispatch({'type': TYPES.LOADING});
lendService.getUserList(params).then((data) => {
dispatch({'type': TYPES.LOADING_STOP});
}).catch((error) => {
dispatch({'type': TYPES.LOADING_STOP});
dispatch({'type': TYPES.SHOW_MESSAGE, text: error.message});
});
}
}
然后看到这种写法
export const getPostByCategory = createAction(
types.FETCH_POSTS_BY_CATEGORY,
async(category, params)=> {
return await postService.getPostByCategory(category, {
pageIndex: 1
});
},
(category)=> {
return {
pending: true,
category
}
}
);
迷茫了,哪种是正确姿势?
官方应该更推荐第一种,配合
redux-thunk
使用。