I tried to setInterval every 15mins but it's not working
const timeInterval = 900_000
useEffect(() => {
const refetch = setInterval(() => {
console.log("Refetch");
}, timeInterval)
return () => clearInterval(refetch)
})
But every 10sec, this's working. How can do that with bigger time like 30mins, 1hour?
const timeInterval = 15 * 60 * 1000
useEffect(() => {
setInterval(() => {
console.log("Refetch");
}, timeInterval)
}, []);
setTimeout and setInterval uses milliseconds. 1000 milliseconds is 1 second, so multiply 1000 by 60 to get 1 minute in milliseconds, and then times that by 15 to get 15 minutes in milliseconds.
const timeInterval = 1000 * 60 * 15;
You need to set your dependency list (which is nothing, []) so, it'll run once on component mount:
const timeInterval = 900_000
useEffect(() => {
const refetch = setInterval(() => {
console.log("Refetch");
}, timeInterval)
return () => clearInterval(refetch)
}, [])