码迷,mamicode.com
首页 > 其他好文 > 详细

React Native(六)——PureComponent VS Component

时间:2017-10-20 12:00:13      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:pad   work   int   block   port   col   pos   fun   str   

先看两段代码:

export class ywg extends PureComponent {
   ……
    render() {
        return (
           ……
        );
    }
}
export class ywg extends Component {
   ……
    render() {
        return (
            ……
        );
    }
}

PureComponent VS Component 

Stateless components may also be referred to as Pure Components, or even Dumb Components, and are meant to represent any React Component declared as a function that has no state and returns the same markup given the same props.

These types of components surprisingly compose a large majority of our applications and, as a result, React 0.14 introduces the ability to write these stateless components as functions, also known as functional stateless components.

So these are some of the UI elements that I summarize from Tencent work.

无状态的组件又被叫做“纯粹的组件”,甚至是“哑巴组件”。这是指这样的一些组件:React组件中有一些被声明为函数(而不是继承自Component的class),它们没有state,只要给定同样的props,就会返回同样的标签块。这种类型的组件出人意料的成为构建大型应用程序的常用方法,所以,自从React 0.14开始支持使用函数的方式来创建这种无状态组件,所以也被叫做“函数式无状态组件”。无状态组件渲染效率更高,编写和组合更加简单

在RN项目中,无论你使用这两者中的哪一种,都无可厚非,关键就是自己在使用时权衡利弊或者是跟团队保持一致就好。

React Native(六)——PureComponent VS Component

标签:pad   work   int   block   port   col   pos   fun   str   

原文地址:http://www.cnblogs.com/zhengyeye/p/7698439.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!