When I try to consume this response in the frontend like customers.NombreCompletoI don't get any data and I can not figure out what am I doing wrong when parsing this; I need the response to be as below.
Code in ReactJS:
const fetchUsers = () => {
var users = [];
axios.get(`https://localhost:7150/api/employees`).then(response => {
users = response.data; // this is an array of users.
});
return users;
}
export const customers = fetchUsers();
Data from API when consuming with axis.get():
[
{
"NombreCompleto": "Jan Murillo Barquero",
"Cedula": "0987654321",
"Telefono": "23213433",
"Direccion": "Alajuela, Alajuela"
},
{
"NombreCompleto": "Gabriel Zuniga Orozco",
"Cedula": "2365123132",
"Telefono": "35435344",
"Direccion": "Heredia, Heredia"
}
]
How I needed, because using this data just like this it does works:
const customers = [
{
"NombreCompleto": "Jan Murillo Barquero",
"Cedula": "0987654321",
"Telefono": "23213433",
"Direccion": "Alajuela, Alajuela",
"avatarUrl": "/static/images/avatars/avatar_3.png"
},
{
"NombreCompleto": "Gabriel Zuniga Orozco",
"Cedula": "2365123132",
"Telefono": "35435344",
"Direccion": "Heredia, Heredia",
"avatarUrl": "/static/images/avatars/avatar_3.png"
}
]