react闲谈——react@15.5.0发布更新说明

前端之家收集整理的这篇文章主要介绍了react闲谈——react@15.5.0发布更新说明前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

还在用react@0.14?

看看react@15.5.0变更了什么内容吧。

(官方更新说明原话)

React

1、Added a deprecation warning for React.createClass. Points users to create-react-class instead.
添加了一个“React.createClass被弃用”的警告,指引用户使用class的方式构建react

//被弃用的写法
var Child = React.createClass({    
    render: function() {
        return React.createElement('div');
    }
})
//推荐的写法
class Child extends React.Component {
    render() {
        return React.createElement('div');
    }
}

也许你还需要在你的package.json文件添加一个插件

"react-create-class": "15.5.0-alpha.2",

2、Added a deprecation warning for React.PropTypes. Points users to prop-types instead.
添加一个“React.PropTypes被弃用”的警告,请使用prop-types代替

3、Fixed an issue when using ReactDOM together with ReactDOMServer.
修复了ReactDOM和ReactDOMServer一起使用的bug

4、Fixed issue with Closure Compiler.
修复了关闭编译器的问题(原来是react导致的,我也遇到命令行自己关闭了的情况)

5、Another fix for Closure Compiler.
修复了编译器出现的其他情况

6、Added component stack info to invalid element type warning.
这句话说的是添加了一个警告,关于组件栈里面的无效元素。

//请注意Foo,Foo只是一个对象,不是一个组件,那么在第7行按照组件的方式调用<Foo />,肯定无法调用。
let Foo = {};
class Button extends React.Component {
  render() {
    return (
      <div>
        <Foo /> // Foo is invalid element
      </div>
    );
  }
}

class DangerButton extends React.Component {
  render() {
    return <Button />;
  }
}

var ExampleApplication = React.createClass({
  render: function() {
    return (
      <div>
        <DangerButton />
      </div>
    )
  }
});

ReactDOM.render(
  <ExampleApplication />,document.getElementById('container')
);

现在增加了比较详细的警告来告诉开发者是哪个js中的哪一行出现了这个错误。类似下面这种提示

warning.js:36 Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: boolean. Check your code at Button.js:8.
    in Button (at DangerButton.js:6)
    in DangerButton (at App.js:10)
    in div (at App.js:9)
    in App (at index.js:7)

React DOM

Fixed Chrome bug when backspacing in number inputs.

Added react-dom/test-utils,which exports the React Test Utils.

React Test Renderer

Fixed bug where componentWillUnmount was not called for children.

Added react-test-renderer/shallow,which exports the shallow renderer.

React Addons

Last release for addons; they will no longer be actively maintained.
Removed peerDependencies so that addons continue to work indefinitely.

Updated to remove references to React.createClass and React.PropTypes

react-addons-test-utils is deprecated. Use react-dom/test-utils and react-test-renderer/shallow instead.

总体来看,没有什么大更新,都是小修小补,剩下的也不翻译了,随便看看就好。。

原文链接:https://www.f2er.com/react/304323.html

猜你在找的React相关文章