简体   繁体   中英

Using spread operator in react/react native (redux)

I am using spread operator in redux for react-native in mobile app development. Is there any possibility that spread operator would not work for some older device that supported by react-native? Not sure how react-native work underlying (does the native app created by react-native depend on underlying browser that support es6??)

What about in react? Assuming that react support that browser version but the browser itself does not support es6 syntax. Would the spread operator in redux be working?

I am thinking should I be using spread operator as I am not sure whether the spread operator is handled by react/react-native or by the browser.

I would want to use spread operator but I do not want:
1) For react-native mobile app, at the end of the day it will not pass QA testing on android 4.4.
2) For react js, at the end of the day it will not work on a browser that it is supported by react js but does not have es6 compatibility.

So my question is does react/react-native handle the spread operator or any es6 function internally or it would be depend on external browser/plugin?

Note: I am talking about .js file not .jsx file in react-native.

For React , you need to worry about using ES6 because the transpilers used such as babel.js are not supported in older versions of browsers and specially Internet explorer. Check the support chart for babel 7 .

For React native things work differently. There's an RCT bridge which helps in converting the javascript/react code into respective native codes for android and ios. So basically everything is converted to native code and then rendered. For react native you dont have to worry about using ES6 syntax as long as your app works on older phones , ie if the APK is supported in older version of android, then the javascript syntaxes would work.

Hope it helps. feel free for doubts

在此处输入图片说明

React

You are right that not all browser support ES6. As a result you code should be transpiled by Babel. Babel will transform all ES6 syntax to browser-compatible JavaScript. See https://medium.com/@SunnyB/how-to-convert-es6-into-es5-using-babel-1b533d31a169

React-native

You code you wrote is actually compiled into other language depending on the platform. At the end of the day, your mobile device is not actually running JS, but Java for example in Android. I am not an expert in the compiling process, but you can have a look here https://hackernoon.com/understanding-react-native-bridge-concept-e9526066ddb8

In short for react-native, you don't need to worrie about it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM