DEV Community

Discussion on: Array.prototype.map() expects a return value from arrow function

Collapse
 
moresaltmorelemon profile image
Ezra Schwepker

Hopefully you've solved it by now, but it is difficult to address your specific issue as your code formatting is broken.

Possible issues:

  • attempting to return an object without wrapping in parenthesis:
// returns object:
() => ({ })
// returns undefined:
() => {}
Enter fullscreen mode Exit fullscreen mode
  • missing return statement
() => {
  return ...
}
Enter fullscreen mode Exit fullscreen mode

An arrow function has an implicit return if no braces ({ }) are used. If braces are used and you intended to return an object rather than defined a code block, then you need to wrap the object in parenthesis (({ })).

If you are using an arrow function with map and returning nothing, then you should either use .forEach instead, or add a return value.