首页 > 解决方案 > 在 reactJS 中返回 undefined 的 Redcuers

问题描述

我的派送有问题。不知何故,即使当我记录要传递的输入值时,它也会返回未定义的值,但我得到了正确的值。

这是我的减速机。

case actionTypes.ADD_COMMENT:
        return {
            ...state,
            posts : [
                ...posts,
                {
                    comment : action.payload.comment,
                }
            ]

        }

export const addComment = (payload : any) => {
return {
    type: actionTypes.ADD_COMMENT,
    payload
}
}

这就是我如何将值传递给调度。

 if (commentValue) {
                let commentVal = commentValue.value
                console.log('--------commentVal', commentVal);
                dispatch(actions.addComment({commentVal}))
            }

有什么建议么?

标签: reactjsredux

解决方案


它应该是

dispatch(action.addComment({comment: commentVal}))

因为您正在访问comment减速器中有效负载上的属性


推荐阅读