zoukankan      html  css  js  c++  java
  • 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>

        )

      }

    }

  • 相关阅读:
    原型设计 + 用户规格说明书
    第三次作业
    MathExam第二次作业
    第一次随笔
    冲鸭第一的合作
    功能规格说明书
    测试与优化
    结对编程
    高分小学计算器
    现实与梦
  • 原文地址:https://www.cnblogs.com/GongYaLei/p/9773176.html
Copyright © 2011-2022 走看看