天天看点

React生命周期

挂载阶段:当组件实例被创建并插入DOM中时 

  · constructor()

  · static getDerivedStateFromProps()

  · render()

  · componentDidMount()

更新阶段:当组件的props或state发生变化时会触发更新

   · static getDerivedStateFromProps()

  · shouldComponentUpdate()

  · render()

  · getSnapshotBeforeUpdate()

  · componentDidUpdate()

卸载阶段:当组件从DOM中移除时 

   · componentWillUnmount()

生命周期:

  render():true( 必须 ),是class组件唯一必须实现的方法,调用此方法才能把JSX内容渲染到页面上

  constructor(): false( 非必须 ),constructor(props),可以在构造函数里初始化state或进行方法绑定

  componentDidMount(): false,会在组件挂载后(插入DOM树种)立即调用,可以在里面发送http请求、设置定时器等操作

上一篇: Vue生命周期

继续阅读