小编Kar*_*koc的帖子

如何在React中清除状态变量?

由于replaceState移除了对支持的支持setState并进行了浅层合并,是否可以删除所有状态变量并通过添加新变量来更新状态(如以下情况this.state),而无需直接更改状态()?

// let's say this.state is { foo: "123", bar: "456", baz: "789" }

// case 1 - this.state is cleared out, all state variables are removed
// this.state is {}

// case 2 - this.state is cleared out and new variable(s) introduced
// this.state is { qux: "lately introduced state variable" }
Run Code Online (Sandbox Code Playgroud)

reactjs

5
推荐指数
1
解决办法
3266
查看次数

标签 统计

reactjs ×1