Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why it possible to use destructuring assignment in React Native?

In the example of react native tutorial, I find syntax which is defined in ECMAScript 2015 (ES6) standard called Destructuring assignment. But as I know, iojs and nodejs do not support this syntax. How can I use it in React Native?

like image 392
ssj Avatar asked Aug 22 '26 05:08

ssj


1 Answers

You are right nodejs and iojs do not support ES6 syntax. But react native:

As of version 0.5.0, React Native ships with the Babel JavaScript compiler.

Read more here

That means that there is another transpiler (Babel) at work in the React packager. It converts from ECMAScript 2015 (ES6) to ES5. This allows you to use the ES6 features like: destructuring, computed property keys, classes, arrow functions, block-scoped variables and more.

If you want to use those features in the React (not Native) app, you will need to include Babel in your project.


Edit:

There is no another transpiler.

React and React Native have both switched their respective build systems to make use of Babel. This replaced JSTransform, the source transformation tool that we wrote at Facebook.

More in Deprecating JSTransform and react-tools

like image 190
knowbody Avatar answered Aug 23 '26 18:08

knowbody



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!