So, I am using hook useState():
const [dailyData, setDailyData] = useState({});
And useEffect() hook to fetch data from API:
useEffect(() => {
const fetchAPI = async () => {
setDailyData(await fetchDailyData())
}
console.log(dailyData)
fetchAPI();
});
But the problem is that these requests are endless.
I'm new in React, so it would be great if you'd explain why this is caused.
Aucun commentaire:
Enregistrer un commentaire