旧:
新:
React16.4版本使用了新的生命周期去掉了三个will钩子,分别是:componentWillMount、componentWillReceiveProps、componentWillUpdate
新的生命周期新增了两个钩子,分别是:
getDerivedStateFromProps:
接受两个参数:props,state 返回一个状态对象或者null,用来修改state的值。 使用场景:若state的值在任何时候都取决于props,那么可以使用getDerivedStateFromProps
getSnapshotBeforeUpdate:在更新前拿到快照(可以拿到更新前的数据)