This repository has been archived by the owner on Apr 6, 2023. It is now read-only.
feat(nuxt3): useFetch
with dynamic reactive request
#3731
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
π Linked issue
β Type of change
π Description
The current version of
useFetch
, only allowed a static value for a request meaning we couldn't assign a dynamic value to the request URL.This PR uses a computed value and
watch
option ofuseAsyncData
(#3722) to automatically trigger refresh whenever request value changes. Main advantage over useAsyncData+fetch is that it automatically tracks dependencies after hydration since we can safely evaluate computed value on client-side without actually evaluating handler and making a double fetch.This PR also improves key generation using unjs/ohash that can also safely hash function values as well for automatically generating fetch key. (however an explicit key is better idea!)
Previously: (still possible to directly pass a value)
New usage:
Next steps:
As is also visible in the example demo, it is not possible to assign dynamic options to ohmyfetch. Therefore options like
params
cannot be dynamic. We could allow computed property, to support{ url, ...options }
in addition of current types (url ref, string, Request)π Checklist