React 0.14 Release Candidate
facebook.github.io
facebook.github.io
In idiomatic React code, most of the components you write will be stateless, simply composing other components. We’re introducing a new, simpler syntax for these components where you can take props as an argument and return the element you want to render:
// Using an ES2015 (ES6) arrow function:
var Aquarium = (props) => {
return <Tank>{getFish(props.species)}</Tank>;
};
// Or with destructuring and an implicit return, simply:
var Aquarium = ({species}) => (
<Tank>{getFish(species)}</Tank>
);
// Then use: <Aquarium species="rainbowfish" />The JSX gets converted to a simple function call.
The automatic semicolon insertion doesn't seem as bad for arrow functions, this works as expected:
() =>
"this string is returned"
I'd personally keep using the parenthesis for aesthetic reasons though. {Aquarium({ species: "rainbowfish" })}
I've come across many projects which defined lots of small react classes, usually with a one or two line render body, which would be better served as simple functions. React.Children.map now returns plain arrays too
Before this change, we would have to do the following when checking the types of children components (in propType validation): const childrenTypes = [];
React.Children.forEach(props.children, child => {
childrenTypes.push(child.type);
});
for (const type of childrenTypes) {
if (type !== MyComponent) {
return new Error(`Child '${type}' is not an instance MyComponent. Check render method of 'ParentComponent'.`);
}
}
It sort of made sense that map() on an opaque data structure would return the same type of data structure but in practice this was rarely useful.Thanks, React team!
var products:Array<Product> = []
for (var x in this.props.products) {
products.push(this.props.products[x])
}I use Redux, where all the state tickles down through the props, so I can probably remove a huge chunk of boilerplate in my apps.
Is there such thing? You at least need to choose between value and ref equality for various props?
Also not clear to me if these functions are turned into full React components with lifecycle methods and async rendering, or are just synchronously invoked in the same render stack frame as the closest up-stack actual React component.
Question for other React devs out there: how long would you typically expect it to be before we can start migrating over?
Will older React components designed for 0.13 still work if they don't include the react-dom package?
- a `ref` of your own component will be the component instance, complete with `getDOMNode`
- a `ref` of React.DOM will be the DOM node
Just seems weirdly confusing.
Refs to custom components will work exactly how they did in 0.13. And getDOMNode is deprecated in general (use React.findDOMNode instead).
I've been using 0.13 in production for half a year with no problems.
The other opportunity is to just call some version 1.0 and then wait some amount of time (a year? two? five?) before making any breaking changes, which sounds less appealing to us. You can always continue to use an older version (and we'll backport serious fixes like we did in http://facebook.github.io/react/blog/2013/12/18/react-v0.5.2...) but we plan to continue developing React and hope that people will continue upgrading to new versions.
If you're concerned about whether it's production-ready (as opposed to future API changes), the answer is definitely yes.
Out of all the release notes this is probably the one that I'm the most excited about. Hopefully this sheds some light on the more confusing warnings (e.g. warnings about missing keys with no real way to determine where they are missing).
https://github.com/facebook/react/tree/v0.14.0-rc1/src/isomo...
We don't use either one outside of the tests.
edit: Derp, they're there already
Am I missing something about how you tell Babel to enable/disable these?
Awesome.
"Universal" has its own share of problems. I'm not sure switching from one wrong and confusing term to another is worth the effort.
React 0.14 supercedes 0.13 but it is not superceded by 0.9.
"Math is pure crap"?
This is a flawed interpretation, but perhaps what wyldfire was trying to demonstrate.
I find this mechanism of versioning mildly irritating (but I wouldn't call it 'crap'). I recognize that it's popular and I just suss the convention from the history.
14 > 13 > 9
But I think we can all take a step back and see the ambiguity right?
Time, as in 00:12 is not a number either, it wraps around in 11:59 (or 23:59 in 24 hour mode)
I'm assuming that's what you're complaining about? I don't know what the React developers are thinking, of course, but I know that whenever I've released something with a 0.x version, it means "this is not stable yet, expect breaking changes". And, if that's a problem for people, they should wait until a 1.x release.
Considering both Facebook and Instagram (as well as a ton of other companies like Netflix) already use it in production for flagship projects, it really should be beyond 0.x land at this point (same argument that applied to node.js, basically).
I guess they just don't want to appear more unstable than AngularJS (which doesn't use semver semantics and thus introduces breaking changes in "minor" releases and thus can get away with calling the upcoming rewrite "2.0").