reactjs - 在 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}))
}
有什么建议么?
解决方案
它应该是
dispatch(action.addComment({comment: commentVal}))
因为您正在访问comment
减速器中有效负载上的属性
推荐阅读
- node.js - GraphQL Apollo 中的多对多关系
- django - 如何在 django 中使用不同表的身份验证
- c# - LINQ Group By 错误的结果
- regex - 在正则表达式上调用 Bool 不像记录的那样工作
- .net - 附加属性未按预期工作
- node.js - 如何比较 MongoDB(NodeJS + mongoose)中的日期?
- asynchronous - 在 FutureBuilder 中获取变量的值并在布局中使用
- go - 如何获得多对多的数据关联
- java - ES Rest High Level Client 空闲一段时间后抛出 SocketTimeoutException
- matlab - for 循环内 while 循环