Everything is working with my cde but I have some very strange behavior that I cannot figure out. My returned promises start off with 1 or 1 and slowly get larger until after about 5 minutes it has over dozens of them. I am using this code...
usePolling(function () {
return Promise.resolve(getData())
}, 4000);
The usePolling function...
function usePolling(fetcher, interval) {
const [payload, setPayload] = useState(null);
React.useEffect(function () {
let timeoutId;
function poll() {
timeoutId = setTimeout(function () {
// you must implement the error handling
fetcher()
.then(function (resp) {
setPayload(resp)
poll();
})
}, interval);
}
poll()
return function () {
clearTimeout(timeoutId);
}
}, [fetcher, interval]);
return payload;
}
and the getData fecthing function...
const getData = () => {
const value = Axios.post("http://localhost:3001/api/get-value",
{user: userProp}).then((response) => {
const recievedData = response.data;
const dataValue = recievedData.map((val) => {
return [val.value]
})
if (loading === true){
setLoading(false);
}
setMoisture(parseInt(dataValue))
console.log("sssssssssssssssss")
return parseInt(dataValue);
})
return value
}
my log starts off like this...
and after a few minutes is like this...
What is causing this??