React_PureComponent 简化 react shouldComponentUpdate 方法,优化性能

PureComponent  与  Component  类似,自react  15.3 版本之后使用,主要为了提高组件的重复加载问题,提高性能,类似于 shouldComponentUpdate功能。

 

import React, { Component, PureCompoent }  from 'react'

class A extends PureComponent {

  constructor(props) {

    super(props);

  } 

  render() {

    console.log("A组件加载")

    return (

      <div>{this.props.data}</div>

    )

  }

}

 

class B extends PureComponent {

  constructor(props) {

    super(props);

  } 

  render() {

    console.log("B组件加载")

    return (

      <div>{this.props.data}</div>

    )

  }

}

 

export   default   class Compoents_1 extends PureComponent {

  constructor(props) {

    super(props);

    this.state={data: 0}

  } 

  render() {

    console.log("B组件加载")

    return (

      <div>

        <A data={this.state.data}></A>

        <B data={this.state.data}></B>

        <button onClick={() => this.setState({data: 2})}></button>

      </div>

    )

  }

}

转载于:https://www.cnblogs.com/GongYaLei/p/9773176.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值