-2

I´m new to javascript and React and wonder simple question what does this line of code do?

I have search about the () and => but dont understand

'export const increment = () => ({ type: "INC" });'

I know the increment variable here will holde the type: "INC" as an array I think but what about the = () =>

jurge bent
  • 45
  • 1
  • 2
  • 9

1 Answers1

0

This is an arrow function. Arrow functions were introduced in ECMAScript 6 and support is relatively recent.

This statement, for example:

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

exports a function named increment. The function takes no arguments, and returns this JavaScript object literal:

{
    type: "INC"
}

The same statement would be written as follows prior to ES 6:

exports.increment = function () {
    return {
        type: "INC"
    }
}
Maxime Launois
  • 928
  • 6
  • 19