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>

        )

      }

    }

  • 相关阅读:
    图灵机器人,web录音实现自动化交互问答
    人工智能初识,百度AI
    flask web 表单验证 WTForms
    websocket的原理
    DBUtils
    【hdu4704】 Sum——费马小定理+快速幂取模
    【hdu3037】Saving Beans——组合数取模
    【SRM15】题解
    【模板】快速幂取模
    【模板】线性筛法求素数
  • 原文地址:https://www.cnblogs.com/GongYaLei/p/9773176.html
Copyright © 2011-2022 走看看