jsdario jsdario - 1 month ago 6
React JSX Question

Spread array destructuring in react-native crashing

The following code:

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

Produces an
unexpected token
error o such line.

[Edit] Why is this?

Thank you.


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.