我是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});
再进行console.logging它们,发现state
现在同时具有data
和test
。
然后,我尝试this.setState({data: someArray});
依次输入“ this.setState({test: someArray});
console”和“ console.log”,发现它们state
又具有data
和test
。
那么,两者之间到底有什么区别?