【问题标题】:React:createClass vs React.Component? why tutorial ignores React.ComponentReact:createClass vs React.Component?为什么教程忽略 React.Component
【发布时间】:2017-01-30 08:05:51
【问题描述】:

为什么在教程中使用 React.createClass 而不是 React.Component?见:

facebook.github.io/react/docs/tutorial.html

每个人都必须放弃 React.createaClass

来自官方文档: https://facebook.github.io/react/blog/2015/03/10/react-v0.13.html

“我们的最终目标是让 ES6 类完全取代 React.createClass,但在我们替代当前的 mixin 用例并支持该语言中的类属性初始化器之前,我们不打算弃用 React.createClass。 ""

【问题讨论】:

    标签: reactjs


    【解决方案1】:

    在稍后的另一篇文章中(你链接的那个是 2015 年 3 月的),他们谈到了 Mixins are considered harmful,这让我相信你应该尽可能地使用 React.Component。这将需要您使用某种构建步骤,因为浏览器不支持 ES2015 类,但除此之外,这是一个改进。阅读我链接的文章,了解为什么以及如何进行切换。

    底线:使用 ES2015(以前称为 ES6)类。

    【讨论】:

    • 谢谢,我不需要 mixins,所以我可以放弃 React.createClass
    猜你喜欢
    • 1970-01-01
    • 2019-08-03
    • 2015-08-20
    • 2017-05-11
    • 1970-01-01
    • 2017-09-12
    • 1970-01-01
    • 2018-01-19
    相关资源
    最近更新 更多