react生命周期

Mounting组件挂载相关的

componentWillMount组件将要挂载。在render函数之前执行,只执行一次,即使多次重复渲染该组件,、

或者改变组件的state的值
componentDidMount
组件已经挂载,在render之后执行,同一个组件重复渲染只执行一次


组件更新相关的
componentWillRecetiveProps(object,nextProps)已经加载组件收到新的props之前调用
,注意组件初始化渲染时不会执行
shouldComponentUpdate(Object nextProps,object nextState)
组件判断是否重新渲染时使用,该组件的接口实际是在组件接收到了新的props或者新的satate的
时候会立即调用
shouldComponentWillUpdate(Object nextProps,object nextState)组件将要更新
componentDidUpdate(Object prevProps,object prevState)
组件已经更新

组件移除
componentWillUnmount在组件将要被移除之前触发,利用该方法来执行一些必要的
清理组件

生命周期中和props和state相关的
getDefaultProps 设置props属性设置
getInitialState 升值state属性初始值


创建阶段只调用getDefaultProps:function()

在实例化阶段
getInitialState    设置this.state的默认值
componentWillMount  在render之前调用
render              渲染并返回一个虚拟的DOM
componentDidMount   在render之后调用,在该方法中react会使用render方法返回的虚拟的dom对象创建真实的DOM结构
                    可以在这个方法中读取dom结点




更新阶段
componentWillReceiveProps
shouldComponentUpdate  如果返回的是false后面的方法则不执行(是否需要更新)
componentWillUpdate
render
componentDidUpdate


销毁阶段
componentWillUnmount


移除组件
React.unmountComponentAtNode(挂载的对象)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值