I'm writing a kibana plugin and I'm facing some trouble with a scheduled function: I want to refresh my page (and getting information from the server) every 5 seconds and to do that I wrote a setInterval inside the useEffect that calls my refresh function.
Now, if I call the refresh function manually (with a button), it works fine, the states are valued correctly and so on. But if I call the refresh function inside the setInterval inside the useEffect, it's like the state are never setted. The hooks set the various state but after 5 seconds, to the next refresh call, the states are empty.
Code, very simple:
useEffect(()=>{
refresh();
setInterval(refresh, 5 * 1000); //called from here, the states are empty, called manually works fine
// and the states are filled correctly
}, []}
const refresh = () => {
//some code with various states update
}