【发布时间】:2021-03-27 04:49:44
【问题描述】:
删除子组件上的“违规”后,我更新了父组件中的状态,但是更改并没有在视觉上更新。在它更新的状态下,不会刷新子组件。这可能与浅层更新有关,但我不确定如何修复它。
我的 updatedData 也更新了,但状态不会立即更新。
谁能帮帮我?
这里是代码
delClick = (id) => {
console.log('id when it come in: ', id);
const updatedData = this.state.students.map((student) => {
return {
...student,
infractions: student.infractions.filter((infraction) => {
return infraction.id !== id;
}),
};
});
console.log('updataed data: ', updatedData);
this.setState({
students: updatedData,
});
console.log('state students: ', this.state.students);
};
【问题讨论】:
-
您能分享一下您所在州的样子吗?
标签: javascript reactjs react-component