It outputs the data in correct format while outputting into console. But while adding to DOM it gives below error, Error: Objects are not valid as a React child (found: object with keys {street, suite, city, zipcode, geo}). If you meant to render a collection of children, use an array instead.
import React from "react";
export default class Fetch extends React.Component {
constructor() {
super();
this.state = { dataList: [] };
}
async componentDidMount() {
let data = await fetch("https://jsonplaceholder.typicode.com/users");
if (data.ok) {
var fetchedData = await data.json();
this.setState({ dataList: fetchedData });
} else console.log("Error");
}
render() {
return (
<table>
{this.state.dataList.map((item) => {
return (
<tr key={item.id}>
<td>{item.id}</td>
<td>{item.name}</td>
<td>{item.username}</td>
<td>{item.email}</td>
<td>{item.address}</td>
</tr>
);
})}
</table>
);
}
}