react 0.14 更新摘要

发布时间:2019-06-07 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了react 0.14 更新摘要脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

React 0.14 更新摘要

react 0.14 changelog简单地记录了下重点。

install

在development环境下react会做warning检查,使用NODE_env=PRoduction来避免检查,提高react的速度。

major change

Two Packages: React and React DOM

拆分为 react react-dom 两个类库。

  • react

  • react-dom

    • render

    • unmountComponentAtNode

    • findDOMNode

    • react-dom/server

      • renderToString

      • renderTostaticMarkup

  • addons 被移到独立的包中

    • react-addons-clone-wITh-props

    • react-addons-create-fragment

    • react-addons-css-transition-group

    • react-addons-linked-state-mixin

    • react-addons-perf

    • react-addons-pure-render-mixin

    • react-addons-shallow-compare

    • react-addons-test-utils

    • react-addons-transition-group

    • react-addons-update

    • ReactDOM.unstable_batchedUpdates in react-dom.

var Zoo = React.createClass({
    render: function() {
        return <div>Giraffe name: <input ref="giraffe" /></div>;
    },
    showName: function() {
        // Previously: var input = this.refs.giraffe.getDOMNode();
        var input = this.refs.giraffe;
        alert(input.value);
    }
});

Stateless functional components

对于简单的无状态的组件(只有一个render函数),提供新的更加简单的语法去声明。

// A functional component using an ES2015 (ES6) arrow function:
var Aquarium = (props) => {
  var fish = getFish(props.species);
  return <Tank>{fish}</Tank>;
};

// Or with destructuring and an implicit return, simply:
var Aquarium = ({species}) => (
  <Tank>
    {getFish(species)}
  </Tank>
);

// Then use: <Aquarium species="rainbowfish" />
  • 表现跟只有一个render函数的组件一样

  • 由于不会创建实例,添加的ref将会返回null

  • 函数声明的组件将没有lifecycle函数,但是可以将.propTypes.defaultProps 设置为该函数的属性

react-tools 被取消

使用 babeljsx 进行编译

breaking changes

  • React.initializeTouchEvents 被移除,默认支持 touch 事件

  • Add-Ons: Due to the DOM node refs change mentioned above, TestUtils.findAllInRenderedTree and related helpers are no longer able to take a DOM component, only a custom component.

会产生警告的改变

  • props 现在不可改变, 使用 React.cloneElement

  • React.children 不支持使用 Plain Object,使用array作为替代。也可以使用 createFragment 来进行迁移

  • Add-Ons classSet 被移除, 使用 classnames

脚本宝典总结

以上是脚本宝典为你收集整理的react 0.14 更新摘要全部内容,希望文章能够帮你解决react 0.14 更新摘要所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。