const newData = data.map((item) => {
return item.id === id ? {
...item, comment, stars, ifCommented: false
} : item
})
this.setState({
data: newData
});//我现在执行了这段代码之后,对应的页面中的数据并没有更新我在orderList这个组件中的handleSubmit这个方法里面,执行了上面那段代码,目的是想让评价按钮变成已评价,但是按钮的状态并没有发生变化.在控制台中打印的是state发生变化了,但是页面中并没有被渲染出来.
按老师的课程学完了,供大家参考
源码 https://github.com/carrieguo/react-demo-my-order.git
ifCommented: false 改成 ifCommented: true