const Cart = ({ details }) => {
let { loading, data } = details;
console.log(data);
return (
<div>
{loading ? (
<p>Load</p>
) : (
<table>
<thead>
<tr>
<th>Id</th>
<th>Title</th>
<th>Completed</th>
</tr>
</thead>
<tbody>
{data.map((d) => {
return (
<tr key={d.id}>
<td>{d.id}</td>
<td>{d.title}</td>
<td>{d.completed ? "OK" : ""}</td>
</tr>
);
})}
</tbody>
</table>
)}
</div>
);
};
export default Cart;
console log of details is:
{
loading: false, data: {…}}
data: {data: Array(3)}
loading: false
"================="
console log of data is
{data: Array(3)}
data: Array(3)
0: {userId: 1, id: 1, title: 'delectus aut autem', completed: false}
1: {userId: 1, id: 2, title: 'quis ut nam facilis et officia qui', completed: false}
2: {userId: 1, id: 3, title: 'fugiat veniam minus', completed: false}
length: 3
I am getting error:
Uncaught TypeError: data.map is not a function
at Cart
As you said "console log of data is {data: Array(3)}" so "data" is an Object, not an Array.
try data.data.map((d) => {...})