react 生命周期

66 阅读1分钟

mounting时期

  1. componentWillMount 在组件即将被挂载到页面的那个时刻自动执行
  2. render 第一次渲染的时候也要执行当state或者props的数据改变的时候也会被执行
  3. componentDidMount 在组件被挂载到页面之后被自动执行

updating时期(即state或者props中的数据发生的时候执行的)

  1. shouldComponentUpdate(nextProps, nextState) 在组件更新之前被自动执行,必须返回一个Boolean值的数据。
  2. componentWillUpdate 在组件更新之且在shouldComponentUpdate之后被自动执行,如 果shouldComponentUpdate返回的时false, 就不再执行该生命周期函数
  3. rende函数也会被执行
  4. componentDidUpdate 在组件更新完成之后被执行。
  5. componentWillReceiveProps 一个组件从父组件中接收参数,首次在父组件渲染不会被 执行,第二次才会被执行

unMounting时期

  1. componentWillUnmount 组件被页面移除之前执行