globalmatt / cutecast

A fun weather forecast app built using React. It's a progressive web app (PWA) that uses kids' drawings to show the current weather!
2 stars 0 forks source link

Make API fetch throttling more robust #32

Open globalmatt opened 1 year ago

globalmatt commented 1 year ago

Currently, weather API calls should in theory be throttled to no more than 1 per second. However, this doesn't work if Context gets stuck in an infinite re-render loop where lastWeatherFetchTime's initial zero value is preserved in a stale closure. This can result in 100's of calls per second.

To fix, store lastWeatherFetchTime in local storage instead. This will make sure the timestamp is always preserved between renders, and even between page reloads.