官术网_书友最值得收藏!

Understanding React Pure Components

Many people get confused by the difference between a Functional Component and a Pure Component. Most of them think they are the same, but this is not true. When we use a Pure Component, we need to import PureComponent from React:

    import React, { PureComponent } from 'react';

If your React component's render method is "pure" (that means it renders the same result, given the same props and state), you can use this function to improve the performance of your application. A Pure Component performs a shallow comparison for the props and nextProps objects as well as the state and nextState objects. Pure components do not include the shouldComponentUpdate(nextProps, nextState) method, and if we try to add it, we will get a warning from React.

In this recipe, we will create a basic example to understand how Pure Components works.

主站蜘蛛池模板: 万安县| 巫溪县| 宝应县| 肥西县| 循化| 蒲城县| 邹城市| 西宁市| 永宁县| 兰州市| 密云县| 寻甸| 出国| 蓝山县| 彭泽县| 卓资县| 灵丘县| 连山| 鄂尔多斯市| 舞钢市| 香港| 克拉玛依市| 伊川县| 阳江市| 沈阳市| 卢湾区| 壤塘县| 陆良县| 常熟市| 舟山市| 札达县| 綦江县| 米林县| 怀化市| 吴忠市| 炉霍县| 齐齐哈尔市| 千阳县| 民权县| 麻江县| 长治市|