N
Nuxt4w ago
Sunny

How to organize query params in useFetch

I have an API with many parameters, so I am using useFetch('/api/myapi', { query: params }). The params is computed and returns all the necessary parameters to fetch the data. This works fine, but these parameters can also be changed from other components. How can I organize these parameters so that the API call automatically triggers when any of them change, but without making multiple API calls if two or more parameters are modified back-to-back? I want to avoid immediate API calls for every single change.
3 Replies
johntanzer
johntanzer4w ago
Hey i think you should look at wrapping in vueuse debounce that is how we solved this there isnt a built in way to do this and there is no plan, did open an issue a while back will see if i can find found it
johntanzer
johntanzer4w ago
GitHub
[useFetch] add delay for default watch · Issue #26686 · nuxt/nuxt
Describe the feature As by default each time you update reactive data that is being used in usefetch - a fetch is called, often one may only want fetch to happen on change after a set amount of tim...
Sunny
Sunny4w ago
This looks promising i'll try it.
Want results from more Discord servers?
Add your server