jsdario jsdario - 1 year ago 112
React JSX Question

Spread array destructuring in react-native errored

The following code:

const [ ...routes, currentRoute ] = props.routes

Produces an
unexpected token
error on such line.

Why is this?

Answer Source

You can use rest operator only at the end of the destructuring expression, e.g.:

const [ currentRoute, ...routes ] = props.routes.reverse()

It is stated in ECMAScript 2015 Spec.#Destructuring Assignment, it could be hard to read but look at ArrayAssignmentPattern structure.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download