react生命周期函数componentWillReceiveProps(通过比较先后传递的props刷新组件)

componentWillReceiveProps这个生命周期函数用的不多,碰到正好总结下。
该函数通过比较先后两次传入的props数值是否相同,执行相应的方法。

如代码所示,比较前一次传入的type, historyData和现在的是否相同,决定是否如何填充echarts options

  componentWillReceiveProps(nextProps) {
    const { type, historyData } = nextProps;
    // eslint-disable-next-line react/destructuring-assignment
    if (this.props.historyData !== historyData || this.props.type !== type) {
      this.handleOption(type, historyData);
    }
  }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值