Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

315
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda