加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

react-native组件与React.createClass的优点和缺点是实现UI组件

发布时间:2020-12-15 20:48:35 所属栏目:百科 来源:网络整理
导读:一个与另一个有什么好处? 是否有人被弃用,我应该使用较新的一个? 我应该创建组件还是React类来开发我的UI? 我看到一些使用Component的例子.例如: export default class ItemList extends Component { constructor(props) { //binding functions this.ren
一个与另一个有什么好处?

是否有人被弃用,我应该使用较新的一个?

我应该创建组件还是React类来开发我的UI?

我看到一些使用Component的例子.例如:

export default class ItemList extends Component {
  constructor(props) {

  //binding functions
  this.renderHeader = this.renderHeader.bind(this);
  this.renderRow = this.renderRow.bind(this);

    super(props);
    this.state = {
      dataSource: this.props.state.planDataSource,planName: null
    }
}

和其他人一起使用

var ItemList = React.createClass({

  getInitialState: function() {
    return {
      dataSource: this.props.state.planDataSource,planName: null
    };
  },

我正在学习反应原生的例子,我很困惑哪个是首选.

我最近将一个React类转换为一个组件,并发现“this”指针不起作用,因为React类使用自动绑定,而Components需要显式绑定.

您应该更喜欢Class而不是createClass,因为它可能会被弃用.

The most notable new feature is support for ES6 classes,which allows developers to have more flexibility when writing components. Our eventual goal is for ES6 classes to replace React.createClass completely,but until we have a replacement for current mixin use cases and support for class property initializers in the language,we don’t plan to deprecate React.createClass.

https://facebook.github.io/react/blog/2015/03/10/react-v0.13.html

No Autobinding

Methods follow the same semantics as regular ES6
classes,meaning that they don’t automatically bind this to the
instance. You’ll have to explicitly use .bind(this) or arrow functions
=>.

No Mixins

Unfortunately ES6 launched without any mixin support.
Therefore,there is no support for mixins when you use React with ES6
classes. Instead,we’re working on making it easier to support such
use cases without resorting to mixins.

https://facebook.github.io/react/docs/reusable-components.html

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读