首页 > 其他 > 详细

React Native(六)——PureComponent VS Component

时间:2017-10-20 11:30:48      阅读:227      评论:0      收藏:0      [点我收藏+]

先看两段代码:

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!