Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

313
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!