-3
export const increment = () => ({
  type: INCREMENT
});

why is ({}) after => instead of {}? can you give me an explanation or say what's this so I can do my research on this? Thank you.

Tom O.
  • 5,730
  • 2
  • 21
  • 35
Roshan
  • 11
  • 2
  • 5
    The curly braces on their own denote a _block_. With the parens surrounding them, it becomes an object that is returned. – evolutionxbox May 27 '21 at 13:34
  • 2
    Does this answer your question? [ECMAScript 6 arrow function that returns an object](https://stackoverflow.com/questions/28770415/ecmascript-6-arrow-function-that-returns-an-object) – evolutionxbox May 27 '21 at 13:34

1 Answers1

1

If you want to return an object from a traditional function this would be

function increment() {
  return {type: INCREMENT};
}

And this works:

export const increment = () => {
  return {
      type: INCREMENT
  }
};

But this wouldnt

export const increment = () => 
  {
      type: INCREMENT
  };

If you want to return an object from an arrow function you can wrap it in ()

Jamiec
  • 133,658
  • 13
  • 134
  • 193