【发布时间】:2018-08-20 22:30:40
【问题描述】:
我正在更新一个帖子,然后当我点击更新时出现此错误
TypeError: Cannot read property 'map' of undefined..
这是我的减速器,有效载荷是
action.payload: {id: 1, title: "test", body: "update"}
case UPDATE_POST:
const updatedItems = state.items.map(item => {
if(item.id === action.payload.id){
return { ...item, ...action.payload }
}
return item
})
return updatedItems
这是我的后期组件渲染
const postItems = this.props.posts.map(post => (
<div key={post.id} className="row">
<div className="container">
<h3>{post.title}</h3>
<p>{post.body}</p>
<button
onClick={() =>this.editPost(post)}
className="btn btn-primary">
Edit
</button>
<button
onClick={() =>this.deletePost(post.id)}
className="btn btn-danger">
Delete
</button>
</div>
</div>
))
【问题讨论】:
-
你能发一个
items数组的样本吗?
标签: reactjs redux react-redux