When I want to access this route http://localhost:3000/programari I get map undefined. I have my object in mmonboDB and I want to display it in a tabel through a map , I don't understand why I can't make it work. I tried to find it here on stack , but I did not succeeded. I didn't use props
When I want to access this route http://localhost:3000/programari I get map undefined. I have my object in mmonboDB and I want to display it in a tabel through a map , I don't understand why I can't make it work. I tried to find it here on stack , but I did not succeeded. I didn't use props
Here is the code :
import Header from "../../header/Header";
import React, { useState, useEffect } from "react";
import axios from "axios";
import { useSelector, useDispatch } from "react-redux";
import {
fetchAllUsers,
dispatchGetAllUsers,
} from "../../../redux/actions/usersAction";
function Profile() {
const auth = useSelector((state) => state.auth);
const token = useSelector((state) => state.token);
const [values, setValues] = useState([
{
date: "",
email: "",
firstName: "",
hour: "",
lastName: "",
phoneNumber: "",
},
]);
const { user, isAdmin } = auth;
const [callback, setCallback] = useState(false);
const dispatch = useDispatch();
useEffect(() => {
if (isAdmin) {
fetchAllUsers(token).then((res) => {
dispatch(dispatchGetAllUsers(res));
});
}
}, [token, isAdmin, dispatch, callback]);
useEffect(() => {
fetch("/programari")
.then((res) => {
if (res.ok) {
return res.json();
}
})
.then((jsonRes) => setValues(jsonRes));
});
return (
<>
<div>
<div className="App">
<Header />
<div className="profile_page">
<h2>
{isAdmin ? "Programari" : "Ne bucuram sa va avem client fidel"}
</h2>
<div style={{ overflowX: "auto" }}>
<table className="customers">
<thead>
<tr>
<th>Nume</th>
<th>Prenume</th>
<th>Telefon</th>
<th>Email</th>
<th>Data</th>
<th>Ora</th>
</tr>
</thead>
<tbody>
{values.map((value) => (
<tr>
<td>{value.date}</td>
<td>{value.email}</td>
<td>{value.firstName}</td>
<td>{value.hour}</td>
<td>{value.lastName}</td>
<td>{value.phoneNumber}</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
</div>
</div>
</>
);
}
export default Profile;