您必须在异步请求结束后分派。
这将工作:
export function bindComments(postId) { return function(dispatch) { return API.fetchComments(postId).then(comments => { // dispatch dispatch({ type: BIND_COMMENTS, comments, postId }); }); }; }解决方法
未处理的拒绝(错误):动作必须是普通对象。使用自定义中间件进行异步操作。
我想在每个帖子中添加评论。因此,当获取帖子运行时,我想为所有帖子调用获取评论API。
export function bindComments(postId) { return API.fetchComments(postId).then(comments => { return { type: BIND_COMMENTS,comments,postId } }) }
评论列表