0

I got a Reactjs code of a class, which saves an array of data per instance. There is a method like addData(data) which just pushes the new data to the array. I have also got a call to setInterval with an action which is supposed to use the data every few seconds, and then delete everything by setting the array to an empty one.

Is there a need in a React app to synchronize the data and protect it with something like a lock in other languages which uses multi threading? If I do need to synchronize the data, how do I do it in React?

CodeMonkey
  • 11,196
  • 30
  • 112
  • 203

1 Answers1

0

Javascript is single threaded.

But be cautious when referencing data like component state from asynchronous calls like setInterval, cause you might get an outdated data.

Vlad Glazov
  • 249
  • 2
  • 6