I have a function that makes a call to the server and retrieves data in a form of array of json objects, what i want is to iterate through the data and display them in the JSX .
Thw Problem is
No thing is being displayed on the screen, not even getting an error. and when I console.log the response i got this:
below is the component
import React from 'react';
import axios from 'axios';
function Supplier(){
let suppliers_list=[];
React.useEffect(() => {
getAllSuppliers();
});
const getAllSuppliers = () =>{
return axios.get('http://localhost:4000/supplier',supplierData).then(
response=>{
let allSuppliers = response.data;
allSuppliers.forEach(element => {
suppliers_list.push(
<li>{element.supplier_name}</li>
);
});
},error =>{
//handle error
}
);
}
return(
<div>
<ul>
{suppliers_list}
</ul>
</div>
)
}
export default Supplier;
and when I console.log the suppliers_list I got this:


useStatehook for yoursuppliers_list. Declaring it as a var means it is not reactive so your component will ignore changes to it.Reactjsplease can you answer it? i tried to useuseStatebut i got errorObjects are not valid as a React child