I have a react app which updates data from a database on a 2 second timer:
componentDidMount() {
this.interval = setInterval(()=> this.getSelPos(), 2000);
}
componentWillUnmount() {
clearInterval(this.interval)
}
async getSelPos() {
const response = await axios.get("http://localhost:5000/selector", { crossdomain: true });
console.log(response.data);
this.setState({SelectorPos: parseInt(response.data.selector)});
this.setState({Pressure: parseInt(response.data.pressure)});
this.setState({Temperature: parseInt(response.data.temperature)});
This just sends to a node api that gets a value from my database and responds. Currently set to poll every 2 seconds and update the page.
The problem I'm running into is that when I tab out or minimise the browser for a few minutes it'll hang for a few seconds on returning, or it'll crash entirely. I suspect this is due to the browser being smart and freezing the tab when not in use. But I'm stumped as to how to fix this issue?