Map State to Props (using arrow function)

Tell us what’s happening:
Tried writing this in arrow function, but it doesn’t work. Not sure why…

Your code so far

const state = [];

// change code below this line
/*function mapStateToProps(state) {
  return {
    messages: state
var mapStateToProps = (state) => {messages: state};

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84 Safari/537.36.

Link to the challenge:

you forgot the brackets

var mapStateToProps = (state) => ({messages: state});

(the brackets are necessary when you are writing short-hand functions)

1 Like

As @hbar1st points out you must wrap the curly brackets with parentheses ( ), because when you use arrow function syntax => { }, JavaScript interprets the { } as a code block instead of something to return. Surrounding the { } lets JavaScript know you want to return what is inside the ( ).

Otherwise, you would have needed to add a return statement like below, which makes the arrow function less concise than it could be.

var mapStateToProps = (state) => { return {messages: state} };

Thanks @hbar1st & @RandellDawson!

I have a better understanding now