Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ES6 and ES7 features without babel transpiling in react-native?

I would love to use Javascript ES6 and ES7 syntax (especially async/await, my new best friends) without transpiling. Is that even an option? And should it be an option?

It all depends on the sub-question: what Javascript engine does react-native effectively use, on Android and iOS? Is it taken from the device itself? (in which case transpiling IS the only option...) Or is it provided by React Native?

like image 887
Merc Avatar asked Dec 22 '17 00:12

Merc


People also ask

What are the new features in ES7?

Array Includes Prior to ES7, the indexof() method of the Array class could be used to verify if a value exists in an array . The indexof() returns the index of the first occurrence of element in the array if the data is found ,else returns -1 if the data doesn't exist.

Does react native support ES6?

React Native uses Babel, the JavaScript compiler, to transform our JavaScript and JSX code. One of Babel's features is its ability to compile ES6 syntax into ES5-compliant JavaScript, so we can use ES6 syntax throughout our React codebase.

What is Babel transpiler or compiler?

Babel is a free and open-source JavaScript transcompiler that is mainly used to convert ECMAScript 2015+ (ES6+) code into a backwards compatible version of JavaScript that can be run by older JavaScript engines. Babel is a popular tool for using the newest features of the JavaScript programming language.


1 Answers

You can happily use async/await in React Native (you've been able to for awhile, in fact... since 0.10). As to using it without transpiling, that's a slightly stickier question. React Native requires only Node v6 and above, so obviously there's a fair bit of transpiling done via Webpack/Babel in order to ensure it still works with older versions of Node.

The deployed environment on the device is JavaScriptCore (see JavaScript Environment for more details). While you're debugging, you're using V8 via Chrome.

like image 150
Rich Churcher Avatar answered Nov 15 '22 08:11

Rich Churcher