我一直试图弄清楚这一点,并没有得到正确的答案.
在以下代码中:
this.setState(prevState => counter: prevState.counter + 1);
prevState是对当前状态的引用吗?或者它是它的副本?变异是好还是应该避免变异?
解决方法
从文件……
prevState is a reference to the prevIoUs state. It should not be
directly mutated. Instead,changes should be represented by building a
new object based on the input from prevState and props.
https://facebook.github.io/react/docs/react-component.html
所以为了回答你的问题,prevState是最后一次突变发生之前的状态.