【发布时间】:2021-01-29 07:14:12
【问题描述】:
使用以下方法有什么区别?
我用它来更新 React 组件状态:
changeRate(id, rate) {
let color = this.state.colors.find((c) => c.id == id);
color.rating = rate;
this.setState({ color });
}
在我正在关注的书中,这是使用的:
rateColor(id, rating) {
const colors = this.state.colors.map(color =>
(color.id !== id) ? color : { ...color, rating })
this.setState({colors})
}
【问题讨论】:
标签: reactjs components state