Hello i have a problem with infinite loops. All the exampels i look at makes the loop go away. But then it wont update my view if i dont refresh. I want the items to appear when something gets added. i thought my example would work but it does not. I dont know how to fix it
const [ReadBookingTimes, SetBookingTimes] = useState([]);
const [readStatus, setStatus] = useState("");
const getBookingTimes = async () => {
try {
const response = await Axios.get(`${API_ENDPOINT}`);
console.log(response);
// debugger;
SetBookingTimes(response.data);
// setStatus("Connection sucsessfull");
} catch (err) {
setStatus("Error getting BookingTimes");
}
};
//reupdate State and prevent infinite loop
useEffect(() => {
getBookingTimes(ReadBookingTimes);
}, [ReadBookingTimes]); //);