• 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>

        )

      }

    }

  • 相关阅读:
    架构师时间~白话OAuth2
    vue前端各种问题
    windows命令行导入sql
    正则表达式概述
    XPath语法 在C#中使用XPath示例
    面试宝典
    Repository,UnitOfWork,DbContext(1)
    EF Code First:实体映射,数据迁移,重构(1)
    表单常用的正则表达式
    Lambda表达式
  • 原文地址:https://www.cnblogs.com/GongYaLei/p/9773176.html
Copyright © 2020-2023  润新知