REACT生命周期函数

116 阅读1分钟

概念:在某一个时刻组件会自动调用执行的函数。

  • initialization
  • Mouting (组件被放到页面时)
  • componentWillMount():在组件即将被挂载到页面的时刻自动执行(只会在第一次挂载时执行)
  • render()
  • componentDidMount():在组件挂载页面之后自动执行(只会在第一次挂载时执行) -Updating

props

  • componentWillReceiveProps()

当该组件从父组件接收了参数且之前已经存在于父组件中才会执行,如果这个组件第一次存在父组件中不会执行。

props\state
  • shouldComponentUpdate()

组件被更新之前执行.返回true,返回false将不会执行下面的生命周期函数,组件也不会被更新。

  • componentWillUpdate()

组件被更新之前执行,但在componentWillReceiveProps() 之后执行,且componentWillReceiveProps()返回true才执行

render()
componentDidUpdate():组件被更新之后执行
-UnMounting
componentWillUnmount() 存在于子组件中,子组件即将从页面中移除时执行。在componentDidUpdate()之前执行
每次更新数据都会重新渲染一次render