When using React Native, you're going to be running your JavaScript code in two environments:
While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.
Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.
As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.
Here's a full list of React Native's enabled transformations.
ES5
promise.catch(function() { });
ES6
<C onPress={() => this.setState({pressed: true})}
let greeting = 'hi';
Math.max(...array);
class C extends React.Component { render() { return <View />; } }
const answer = 42;
var {isActive, style} = this.props;
for (var num of [1, 2, 3]) {}
import React, { Component } from 'react';
var key = 'abc'; var obj = {[key]: 10};
var obj = { method() { return 10; } };
var name = 'vjeux'; var obj = { name };
function(type, ...args) { }
var who = 'world'; var str = `Hello ${who}`;
ES7
var extended = { ...obj, a: 10 };
function f(a, b, c,) { }
async function doStuffAsync() { const foo = await doOtherStuffAsync(); }
;Specific
Many standards functions are also available on all the supported JavaScript runtimes.
Browser
ES6
ES7
Specific
__DEV__
You can edit the content above on GitHub and send us a pull request!