Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

314
Vistas
Getting Destructuring error with Rest operator?

I assume this must be destructuring using a rest statement? what exactly is this doing? The problem is, I get an error in WebStorm:

const cars = {...this.state.cars}

Error: Unexpected token

it's referring to the first {

Here's the react component method:

addCar(car){
    const cars = {...this.state.cars};
    const timestamp = Date.now();
    cars[`car-${timestamp}`] = car;
    this.setState({ cars })
  }

I do have babel setup and working because everything else seems to work fine such as import, etc.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

It's the spread properties syntax and it's creating a shallow copy of this.state.cars. That means that this line:

cars[`car-${timestamp}`] = car;

doesn't result in an additional key being added to this.state.cars. That is, it's being used specifically so that this.state.cars is not mutated.

For spread properties to be included in your Babel configuration, you'd need to be using the babel-plugin-syntax-object-rest-spread and babel-plugin-transform-object-rest-spread plugins - which are included in the stage-2 preset.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda