0

I have a sample_data.json(this json file is located in my local HDD) file which I can read from my React JS project.

Now the problem is, if I change the data of the sample_data.json file, how can I fetch the updated data in my project?

I already use setInterval method to read the json file after with a 5secs interval. But it fails to read the modified json file.

this.timer = setInterval(()=> this.beginSampleData(), 5000);
Atahar Hossain
  • 336
  • 3
  • 11

1 Answers1

0

If you import the JSON as a file in your React Project, it will not update until you rebuild the project (or have hot-reloader enabled - but not something you want on a production app). If you want to load the file on the fly, you need to create a nodejs server, create an API that reads the file (see more details on how here: Proper way to return JSON using node or Express) then from your react app fetch it from this endpoint instead of the file directly.

Arber Sylejmani
  • 2,078
  • 1
  • 16
  • 20