7

I saw this piece of code in React, like

connect(mapStateToProps, {
    test: () => {return { type: 'TEST_ACTION' }}
})(Index);

but I failed to google any explanation. Probably the question is dumb, but I appreciate any help, maybe links to some existing explanations or examples.

Battle_Slug
  • 1,801
  • 23
  • 52
  • its just an ecmascript6 function – juvian Nov 23 '15 at 20:03
  • http://www.ecma-international.org/ecma-262/6.0/#sec-arrow-function-definitions – Sampson Nov 23 '15 at 20:05
  • Sorry, I really searched, but I didn't get the link you proposed. – Battle_Slug Nov 23 '15 at 20:09
  • @Battle_Slug: Yeah, I did a search before answering as well. :-) Guess I rushed too much (I was heading out). (If you un-accept it, I'll delete the answer, doesn't really add anything over the answer in the linked question.) – T.J. Crowder Nov 23 '15 at 22:14
  • 1
    @T.J.Crowder Actually, I think if people vote, probably they also fail to find another link explaining the matter, so this thread still might be helpful, including your short answer, which for me is precise enough to understand what i want. Sure, if it's against the rules, we'll do what you're proposing ) – Battle_Slug Nov 23 '15 at 22:38
  • @Battle_Slug: No worries. :-) – T.J. Crowder Nov 24 '15 at 08:01

1 Answers1

8

That's an ES2015 (aka ES6) arrow function. It's a function expression that inherits this (and arguments, and a few other things) from the context where it's created. So basically:

test: function() { return { type: 'TEST_ACTION' }; }

...but using the newer syntax that would handle this differently, if it used this.

T.J. Crowder
  • 879,024
  • 165
  • 1,615
  • 1,639