0

I've tried to rewrite the following code according to ES6. I keep getting ESLint warnings, and I've spent about 20 minutes on it so far, I'm not quite sure how to write it...

  .then(result => {
    const [categories, properties, placements] = result.map(r => r.data);

    this.properties = properties.map(property => {
      {
        ...property,
        category: categories.find(c => c.id === property.category_id),
        property: placements.filter(p => p.property_id === property.id),
      }
    });
  });

The code above just doesn't parse at all, but depending on what I've tried it says I can't use return {} in an arrow function.

If I try to just modify the argument I get an error to no-param-reassign

Tallboy
  • 12,847
  • 13
  • 82
  • 173

1 Answers1

0

I realized I can run eslint fix to see how it would be done:

        this.properties = properties.map(property => ({
          ...property,
          category: categories.find(c => c.id === property.category_id),
          property: placements.filter(p => p.property_id === property.id),
        }));

Tallboy
  • 12,847
  • 13
  • 82
  • 173
  • To return an object from an arrow function, you either need to wrap the object in parentheses (like you did here) to avoid confusion with a function body or use the `return` keyword from within the function body. – Elan Hamburger Sep 06 '20 at 20:23