0

I am using React and fetching data from an API which has a limit of 50 calls per minute and my app is consuming most of them when load the page that displays that data because it is organized in a table and each line is an HTTP request to the API (see screenshot):

enter image description here

Obviously the problem is that when the user refreshes within 1 minute most of the data doesn't load and the console is flooded with cors error.

I thought to write a node.js script that fetches the data every minute and write it into a file so the front end can use it without issues but how would I do it without writing a backend script?

How can I write every minute into a file to store the fetched API data without incurring into the problem that each time the user refreshes the page the 1 minute timer resets?

1 Answer 1

1

for this problem, you can use the useInterval hook and give it time to repeat the fetching operation in the specified duration. You can find the hook in the link below.

https://overreacted.io/making-setinterval-declarative-with-react-hooks/

Sign up to request clarification or add additional context in comments.

1 Comment

That is good, but the thing is that even with using useInterval and write the API data into a json file, if the user refreshes the page within 60 seconds, the setInterval restarts from zero and it will attempt to rewrite again into json but it will not write anything because the 60 seconds have not passed and the API returns cors error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.