由于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 ×1