React component lifecycle methods

Three phase 1, component lifecycle

  1. Mounting (loading stage)
  2. Updating (update phase)
  3. Unmounting (unloading phase)

2, the old life cycle

image description

Mounting (loading phase: relates hook function 6)

constructor()

加载的时候调用一次,可以初始化state

getDefaultProps()

设置默认的props,也可以用dufaultProps设置组件的默认属性。

getInitialState ()

初始化state,可以直接在constructor中定义this.state

componentWillMount()

组件加载时只调用,以后组件更新不调用,整个生命周期只调用一次,此时可以修改state

render()

react最重要的步骤,创建虚拟dom,进行diff算法,更新dom树都在此进行

componentDidMount()

组件渲染之后调用,只调用一次

Updating (update phase: involving 5 hook function)

Guess you like

Origin blog.csdn.net/p445098355/article/details/105217725