前端面经 React常见的生命周期
初始化阶段
- constructor state的初始化,防抖节流的绑定
- getDerivedStateFromProps 静态函数 当作纯函数使用 传入props和state,合并成一个新的state
- componentWillMount 组件如果有getDrivedStatefromprops不会执行
针对一些接口的预请求时使用 - render
- componentDidMount
更新节点
-componentWillReceiveProps props变化时执行
组件如果有getDrivedStatefromprops不会执行
-
shouldComponentUpdate:拦截器,返回一个布尔值
-getSnapShotBeforeUpdate:更新快照 获取更新之前的一些数据 -
componentWillupdate
-
componentDidupdate
销毁阶段
-componentWillUnmount阶段 闭包定时器销毁