The code below get records from a web api. That's work, I get back the only record. But I don't understand why the WebApi is called 8 times.
Do you have an idea why ?
const Customer = () => {
const [httpRequestDone, setHttpRequestDone] = useState(false);
const [data, setData] = useState([]);
if (!httpRequestDone) {
axios({
method: 'get',
url: 'https://localhost:44368/api/Customer/AllCustomers',
})
.then(res => {
console.log(res.data);
setData(res.data);
setHttpRequestDone(true);
});
}
return (
<div className="customer">
<Navigation />
<ul>
{data.map(item => (
<li key={item.customerId}>
<div>{item.customerId}</div>
<div>{item.lastName}</div>
</li>
))}
</ul>
</div>
);
};
export default Customer;