DEV Community

kartikkumar2021
kartikkumar2021

Posted on

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

import React, { useState, useEffect } from 'react';
import { Table } from "react-bootstrap";

export default function Users() {
const [data, setData] = useState([])
useEffect(() => {
let url = "https://jsonplaceholder.typicode.com/users"
fetch(url).then((response) => {
response.json().then((result) => {
console.warn(result)
setData(result)
})
})
}, [])
return (


User Component












{
data.map((item) => {






})
                }
            </tbody>
        </Table>
    </div>
)

}


Id Name Email Address
{item.id} {item.name} {item.email} {item.address.street}

Top comments (2)

Collapse
 
kartikkumar2021 profile image
kartikkumar2021

can anyone solve this issue?

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.