I am trying to setState
on a given time interval (100ms). I have discovered both in practice and through research that setInterval
is inaccurate, and will float over time. I need it to be accurate because I'm aiming to have data (from an array) in my app synced up to a video.
Here is what I currently have:
data = this.processCSV(text);
let idx = 0
this.intOne = setInterval(() => {
this.setState(previousState => (
{
data1: parseFloat(data[idx][2]),
data2: parseFloat(data[idx][1]),
data3: parseFloat(data[idx][3])
}
));
idx = idx + 1;
}, 100);
In my research, I've found a few solutions that use Date
to accurately keep track of time and account for drifting.
Expected Results: setState
is called 10 times per second for an extended amount of time
Current Results: setState
is called ~9 times per second and continues to float away from expected time