react的生命钩子

recat的生命周期

react 的生命周期分为初始化(initial),更新(update)和销毁(unmount)

initial之前

  • getDefaultProps
    获取默认的props

    initial阶段会调用的生命钩子

    • getInitialState
      获取初始的state
    • componentWillMount
      组件将要安装
    • componentDidMount
      组件已经安装

      update阶段会调用的生命钩子

  • props发生改变
    • componentWillReceiveProps
      组件将要接受props
    • shouldComponentUpdate
      组件是否要更新
      //shouldCompontUpdate钩子调用后返回一个boolean     
      //  ====> false 继续运行
      //  ====> true  执行渲染操作
      
    • 渲染操作
    • 渲染操作
    • componentWillUpdate
      组件将要更新
    • componentDidUndate
      组件已经更新
    • 运行
  • state发生改变
    • shouldComponentUpdate
      组件是否要更新
      //shouldCompontUpdate钩子调用后返回一个boolean     
      //  ====> false 继续运行
      //  ====> true  执行渲染操作
      
    • 渲染操作
      react的生命周期