当前位置: 代码迷 >> 综合 >> react学习笔记(三)生命周期
  详细解决方案

react学习笔记(三)生命周期

热度:93   发布时间:2023-12-09 03:00:08.0

react的生命周期

从组件诞生到移除:

组件的生命周期可分成三个状态:

?Mounting:已插入真实 DOM

?Updating:正在被重新渲染

?Unmounting:已移出真实 DOM


?挂载:

1、componentWillMount 组件挂载之前被调用

2、componentDidMount 在挂载结束被调用,DOM节点初始化操作应该在这里

?更新:

1、componentWillReceiveProps 更新props时被调用,render时不会被调用

2、shouldComponentUpdate(门神),要返回true||false来判断是否允许更新,第一个参数,nextProps,第二个nextState

3、componentWillUpdate 更新发生之前被调用

4、componentDidUpdate 组件完成更新后立即调用。在初始化时不会被调用。

?移除

componentWillUnmount 组件移除时被调用



  相关解决方案