0👍
i solve my problem just making theupdate inside the function of the request
useEffect(() => {
let interval,aux=[],count=0;
if(clase==='content-layout active'){
interval = setInterval(() => {
axios
.get( `/custom/balance`)
.then(response => {
if(response.data!==undefined && response.data.length>0 ){
aux=response.data.slice(response.data.length-15)
setBalance(response.data.slice(response.data.length-15))
setnewValue(aux[aux.length-1].balance)
if(count%3==0){
myAreaChart.data.labels.shift()
myAreaChart.data.datasets[0].data.shift()
}
myAreaChart.data.labels.push("");
myAreaChart.data.datasets[0].data.push(aux[aux.length-1].balance);
count+=1
myAreaChart.update();
}
}
).catch(error=>{
console.log(error)
})
}, 2000);
}
return()=>{
clearInterval(interval);
}
// eslint-disable-next-line
}, [clase]);
Source:stackexchange.com