2

I've seen this a few times with redux code:

const mapDispatchToProps = (dispatch) => {
  ...
}

function mapStateToProps(state) {
  ...
}

Is there any reason why this is done, is it just a convention, a case of copy-paste code, or is there some benefit to doing it this way?

I've read that arrow functions vs regular functions automatically bind this, but it doesn't appear that these functions exist within a class at all, so maybe that makes no difference?

kinabalu
  • 428
  • 1
  • 5
  • 10
  • Are you referring to declarative v expressive creation of a function or using 2015 fat arrow syntax? – 1252748 Jan 04 '17 at 02:17
  • my question was in the specific usage with redux and the conventions that I've seen throughout. Does it matter if both are using the arrow function declaration? is there any reason to use one over the other specifically taking redux into account – kinabalu Jan 04 '17 at 02:29

1 Answers1

0

I think it's a matter of taste; aside from the obvious differences (ex. function expressions won't be hoisted) both work pretty much the same in your case.

Taking into account, the former syntax causes the interpreter to raise a SyntaxError if you try to redefine the constant whereas re-declaring a function (silently) replaces the previously declared one.

fardjad
  • 20,031
  • 6
  • 53
  • 68