如果我理解正确,组件的 React 生命周期应该确保componentDidMount在componentWillReceiveProps. 当我在组件的初始安装上测试它时,它似乎是这样工作的。但是当组件之前已经安装并重新安装时,顺序是相反的。这是预期的行为吗?下面的一段代码说明了一个可以通过这种方式引入的潜在错误:
class Example extends React.Component {
    componentDidMount() { 
        this.something = { foo: 'bar' };
    }
    componentWillReceiveProps(nextProps) {
        this.something.foo;
        // Throws a TypeError if this code is reached before
        // componentDidMount is called.
    }
}