I am trying to create a simple CRUD MERN Application. In this application data is displayed in my console, but I want it in my UI part.
This is Alluser.js file where I want to display console data which is coming from my backend:
import React, { useEffect, useState } from "react";
import { Link } from "react-router-dom";
import { getUsers } from "./api";
const UserData = () => {
const [users, setUser] = useState([]);
useEffect(() => {
AllUsers();
}, []);
const AllUsers = async () => {
const response = await getUsers();
console.log(response.data);
setUser(response.data);
};
return (
<div>
<div className="container">
<table className="table table-hover table-bordered mt-3">
<thead>
<tr>
<th scope="col">No</th>
<th scope="col">Name</th>
<th scope="col">Email</th>
<th scope="col">Phone</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
{users.map((index,user) => {
<tr key={index}>
<th scope="row">{user.id}</th>
<td>{user.email}</td>
<td>{user.name}</td>
<td>{user.phone}</td>
</tr>;
})}
</tbody>
</table>
</div>
</div>
);
};
export default UserData;
