【问题标题】:Why, after clicking the button "update State" the state inside the super doesnt update to sliced array instead console logs entire array?为什么,单击按钮“更新状态”后,超级内部的状态不会更新为切片数组,而是控制台记录整个数组?
【发布时间】:2022-08-10 16:51:16
【问题描述】:
在下面的给定图像中
为什么单击updatestate按钮后,状态没有更新为切片数组[\'usa\',\'china\'],而是更新到console.log中的整个数组,但在页面上却正确显示。 ?
标签:
javascript
reactjs
class
【解决方案1】:
第 10 行和第 11 行称为 mutating states,这与 React 推荐的更新状态的方式背道而驰,因此它可能有效,也可能无效。