📜 ⬆️ ⬇️

React v0.14 release candidate overview

We are glad to present you our first release candidate for React 0.14! We published an announcement of the upcoming changes in July, but now we have stabilized the release even more and we would like you to try it before we release the final version.

Let us know if you have any problems by creating a task in our GitHub repository.


Installation


We recommend using React via npm and using utilities such as browserify or webpack to build your code in one package:
')
npm install --save react@0.14.0-rc1 npm install --save react-dom@0.14.0-rc1 

Remember that by default, in development mode, React runs additional checks and provides useful warnings. Therefore, when deploying your application, set the NODE_ENV environment variable in production to use the production mode, in which React does not include service warnings and runs much faster.

If you cannot use npm , we also provide compiled builds for browsers for your convenience:


These builds are also available as bower packages: react and react-dom

Major changes



Two packages: React and React DOM


When we look at modules such as react-native , react-art , react-canvas and react-three , it becomes clear that the beauty and essence of React has nothing to do with browsers or DOM.

To make it more transparent and easier to use in more environments where React can render, we have divided the main react package into two: react and react-dom .
This opens the way for writing components that can be shared in the web versions of React and React Native. We do not assume that all the code in the application should be shared, but we want to be able to share components that behave the same on different platforms.

The react package contains React.createElement , .createClass , .Component , .PropTypes , .Children, and other element-oriented and component-oriented helpers. We think of them as isomorphic or universal helpers that you need to build components.

The react-dom package contains ReactDOM.render , .unmountComponentAtNode, and .findDOMNode . In react-dom / server , we have support for server rendering using ReactDOMServer.renderToString and .renderToStaticMarkup .

 var React = require('react'); var ReactDOM = require('react-dom');</p> <p>var MyComponent = React.createClass({ render: function() { return <div>Hello World</div>; } }); ReactDOM.render(<MyComponent />, node); 


We published an automated codemod script that we use on Facebook for this transition.

Add-ons were moved to separate packages: 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- mix , react-addons-shallow-compare , react-addons-test-utils , react-addons-transition-group and react-addons-update , as well as ReactDOM. unstable_batchedUpdates in react-dom

At the moment, please use certain versions of react and react-dom in your applications to prevent problems with versioning.

Links to DOM nodes


Another important change we made in this release is that the references (refs) to the DOM components now refer to the DOM node itself.
What this means: we looked at what you do with the reference (ref) to the React DOM components and realized that the only useful thing you can do with it is to call this.refs.giraffe.getDOMNode () to get the DOM node. In this release, this.refs.giraffe is the current DOM node.
Please note that links to custom (user-defined) components work the same as before; only native DOM components fall under this change.

 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); } }); 


This change also applies to the return result of ReactDOM.render when we pass the DOM node as the root component. As with refs, these changes do not apply to custom components. With these changes, we declare the .getDOMNode () method unsupported and replace it with the ReactDOM.findDOMNode method (see below).

"Stupid" components


In the typical React code, most of the components that you write should not have their own state, so-called. stateless. We present a new, simpler syntax for such components, in which you can pass props as an argument and return the element that you want to draw:

 //  ES2015 (ES6)  : var Aquarium = (props) => { var fish = getFish(props.species); return <Tank>{fish}</Tank>; }; //      : var Aquarium = ({species}) => ( <Tank> {getFish(species)} </Tank> ); //  : <Aquarium species="rainbowfish" /> 


This pattern is designed to encourage the creation of these simple components that should make up most of your applications. In the future, we will also be able to optimize performance, specifically for these components, while avoiding unnecessary checks and memory allocation.

React-tools is no longer supported.


The react-tools package and the browser version JSXTransformer.js are undesirable . You can continue using them in version 0.13.3 , but we no longer support them and recommend switching to using Babel , which has built-in support for React and JSX.

Compiler optimization


React now supports two compiler optimizations that can be included in Babel 5.8.23 and higher. Both of these transformations should be included only in production (for example, before minification) because, although they improve execution performance, they make service warnings more hidden and skip important checks that occur in development mode, including propTypes.

Embedding React elements: optimization.react.inlineElements converts JSX elements to objects such as {type: 'div', props: ...} instead of calling React.createElement .

Constant “ascent” of React elements: optimization.react.constantElements “raises” the creation of elements to the upper level of subtrees, which is completely static, which reduces the calls to React.createElement and movement. More importantly, it informs React that the subtree has not changed, so React can completely skip it when negotiating.

Critical changes


As usual, we have several critical changes in this release. Whenever we make big changes, we warn at least one release, t.ch. You have time to update your code. The Facebook code base is more than 15,000 React components, so in the React team, we always try to minimize the consequences of critical changes.

These three critical changes caused warnings in version 0.13, so you don’t need to do anything if your code has no warnings:


And these two changes were not diagnosed in 0.13, but they will be easy to find and fix:


New exceptions displayed in warnings




Significant improvements




New useful warnings




Significant fixes




Posted by: Ben Alpert

Source: https://habr.com/ru/post/266683/


All Articles