reactjs – React.Component和React.createClass

我困惑了什么是组件和反应类之间的区别?

我什么时候在反应类上使用组件?
看起来组件是一个类,createClass创建一个组件。

https://facebook.github.io/react/docs/top-level-api.html

React.Component

This is the base class for React Components when they’re defined using
ES6 classes. See Reusable Components for how to use ES6 classes with
React. For what methods are actually provided by the base class,see
the Component API.

React.createClass

Create a component class,given a specification. A component
implements a render method which returns one single child. That child
may have an arbitrarily deep child structure. One thing that makes
components different than standard prototypal classes is that you
don’t need to call new on them. They are convenience wrappers that
construct backing instances (via new) for you.

他们是做同样的事情的两种方式。

React.createClass是一个返回一个Component类的函数。

MyComponent = React.createClass({
  ...
});

React.Component是您可以扩展的现有组件。当使用ES6时主要有用。

MyComponent extends React.Component {
  ...
}

相关文章

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