arrow function syntax {()} and ({})

Viewed 57

I was wondering whats the difference of having:

export const mapStateToProps = ({some}) => ({})

and

export const mapStateToProps = ({some}) => {()}

1 Answers

({some}) => ({}) defines a "concise" arrow function (one with an expression body) returning an object that's defined by the object initializer.

({some}) => {()} defines a "verbose" arrow function (one with an explicit function body, e.g. {...}) containing just () and not returning anything. (That particular one is invalid, the () must have something inside them. It's also slightly odd — though syntactically valid — to have a freestanding (...) expression as a statement.)


The ({some}) parameter list which is the same between the two is a destructuring parameter list: The function expects an object and retrieves the some property from that object.

Related