React10组件生命周期

  • componentWillMount  组件将要挂载 不能进行dom操作
  • componentDidMount  组件已经挂载 可以对DOM进行操作
  • componentWillReceiveProps  父组件传递的属性有变化,做相应响应
  • shouldComponentUpdate  组件是否需要更新,返回布尔值  返回true更新,返回 false不更新,这是一个优化点。
  • componentWillUpdate 组件将要更新
  • componentDidUpdate  组件已经更新
  • componentWillUnmount  组件已经销毁
  • 组件初始化触发顺序:
            《1》 constructor 构造函数
            《2》 componentWillMount 
            《3》 render函数渲染
            《4》 componentDidMount 
  •  组件接收的prop更新,触发顺序
            《1》componentWillReceiveProps 
            《2》shouldComponentUpdate 
            注意:如果shouldComponentUpdate里面返回false,则不往下触发,到此为止。如果返回true,则往下触发。
            《3》componentWillUpdate
            《4》render函数渲染
            《5》componentDidUpdate 
  • componentWillUnmount触发时机
            父组件中利用三目运算将子组件销毁:
            
        此时会触发子组件的componentWillUnmount钩子。
  • 子组件state改变,需要重新渲染则会直接触发shouldComponentUpdate,然后看该钩子中返回的是true还是false,来决定是否进行更新操作componentWillUpdate=》render函数渲染=>componentDidUpdate 
 

猜你喜欢

转载自www.cnblogs.com/tengfeiS/p/12149870.html