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

一个与另一个有什么好处?

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

我应该创建组件还是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

相关文章

一、前言 在组件方面react和Vue一样的,核心思想玩的就是组件...
前言: 前段时间学习完react后,刚好就接到公司一个react项目...
前言: 最近收到组长通知我们项目组后面新开的项目准备统一技...
react 中的高阶组件主要是对于 hooks 之前的类组件来说的,如...
我们上一节了解了组件的更新机制,但是只是停留在表层上,例...
我们上一节了解了 react 的虚拟 dom 的格式,如何把虚拟 dom...