我是 React.js 库的新手,我正在阅读一些教程,我遇到了:
this.setState
this.replaceState
给出的描述不是很清楚(IMO)。
setState is done to 'set' the state of a value, even if its already set
in the 'getInitialState' function.
相似地,
The replaceState() method is for when you want to clear out the values
already in state, and add new ones.
我尝试this.setState({data: someArray});
了this.replaceState({test: someArray});
follow 和 console.logged 它们,我发现state
现在有data
和test
。
然后,我尝试this.setState({data: someArray});
了this.setState({test: someArray});
follow 和 console.logged 它们,我发现它又state
同时具有data
和test
。
那么,两者究竟有什么区别呢?