不常用的生命周期方法
挂载时
- 静态方法 static getDerivedStateFromProps 会在 constructor 之后 render 之前调用
- static getDerivedStateFromProps 静态方法接收两个参数父组件传递过来的 props 和自身的 state
- static getDerivedStateFromProps 方法返回的内容会自动合并到 this.state 上
更新时
- 调用静态方法 static getDerivedStateFromProps
- 调用 shouldComponentUpdate ,该方法接收更新后的 props 和 state ,如果该方法返回 true 则会继续调用 render 方法渲染组件,如果返回 false 则不会调用 render 方法渲染组件
- 调用 getSnapshotBeforeUpdate 该方法会在 render 方法之后调用,该方法接收更新之前的 props 和 state 作为参数,并将返回值传递给 componentDidUpdate 的第三个参数
posted @
2021-12-05 00:09
霸哥yyds
阅读(
42)
评论()
收藏
举报