MLH-Fellowship / prep-project-4.1.3

MLH Prep Project for Pod 4.1.3
https://mlh-prep-4-1-3.netlify.app/
MIT License
3 stars 10 forks source link

Fetch weather only when user finishes input #16

Closed iamwyh2019 closed 3 years ago

iamwyh2019 commented 3 years ago

Our site fetches weather data whenever the input box is changed. Say when user types "Chicago", it calls the api for "C", "Ch", "Chi", etc. This causes lots of unnecessary calls and easily exceeds free API limit. I suggest we only fetch the weather when user completes input. We can add a timer that calls useWeather in one second (something like setTimeout), and when the input box is changed the timer is reset.

grace-omotoso commented 3 years ago

@GrayFlash and Co. due to the criticality of this issue, I reassigned to Sumana and Co. The way we currently consume our API is too expensive.

sumana2001 commented 3 years ago

Hey @grace-omotoso @Young-Einstein10 and @Shubh4m-B have already solved this issue by using debounce in their PR #15. They have added a function where if the search term has not been updated for more than 500ms, then only the API will be called. If you want we can increase that time a bit, but other than that, I think all the work has been already done by them. Let me know what you think.

Screenshot 2021-11-18 at 4 43 16 PM
grace-omotoso commented 3 years ago

@sumana2001, no worries. I will close this issue