Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spread operator in react throwing error of Unexpected token

Tags:

Here is the code where I have included spread operator

style={{ ...styles.detailsRow.icon, alignSelf: 'centre' }} 


What things do I need to install or add to make it run?

And also what is its equivalent in es2015?

like image 965
user17422 Avatar asked Jul 20 '16 21:07

user17422


People also ask

What is Pread operator?

The JavaScript spread operator ( ... ) allows us to quickly copy all or part of an existing array or object into another array or object.

What spread operator returns?

In case of arrays,this method does not change the existing arrays but instead returns a new array.

How does the spread operator work in ES6?

JavaScript ES6 (ECMAScript 6) introduced the spread operator. The syntax is three dots(...) followed by the array (or iterable*). It expands the array into individual elements. So, it can be used to expand the array in a places where zero or more elements are expected.


1 Answers

You need to configure Babel to use the transform-object-rest-spread plugin. Refer to the following link for details: https://babeljs.io/docs/plugins/transform-object-rest-spread/

like image 101
const314 Avatar answered Oct 01 '22 23:10

const314