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

reactjs – React.Component和React.createClass

发布时间:2020-12-15 06:41:22 所属栏目:百科 来源:网络整理
导读:我困惑了什么是组件和反应类之间的区别? 我什么时候在反应类上使用组件? 看起来组件是一个类,createClass创建一个组件。 https://facebook.github.io/react/docs/top-level-api.html React.Component This is the base class for React Components when t
我困惑了什么是组件和反应类之间的区别?

我什么时候在反应类上使用组件?
看起来组件是一个类,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 {
  ...
}

(编辑:李大同)

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

    推荐文章
      热点阅读