-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(nuxt): add immediate
option for useAsyncData
and useFetch
#5500
Conversation
✅ Deploy Preview for nuxt3-docs ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
Hi @Vl4dimyr and thanks for the PR. It for sure makes sense to make a lazy executed version of asyncData/fetch but I'm afraid it might introduce behavior inconsistencies if we directly introduce this option directly for existing What do you think if we introduce a new composable such as |
Thinking about the use case mentioned in the nuxt/nuxt#14333, to me an
What about introducing another boolean option called Going even further, if the On the other hand, the approach outlined by @pi0 which is introducing a new composable might be a better idea. I really struggle to have preference of one solution over the other. |
I'm not sure what would be better between introducing a new My use-case would be passing What can I do to help move this PR closer to merging ? |
@pcouy Would you please share your use case in linked issue nuxt/nuxt#14090? A code example or sandbox would be nice 🙏🏼 As I mentioned earlier, such functionality makes sense but it is not what currently |
Sorry, it took long to be back on this feature. I was thinking more, introducing more composables for data fetching would be ultimately confusing more even. And adding this flag is not adding much overhead and covers use cases. I've made a rebase added basic tests and a refactor that (BTW nothing is set on stone. Feedback is more than welcome until we reach 3.0.0 to refine API) |
🔗 Linked issue
❓ Type of change
📚 Description
If the newly added option
immediate
is set tofalse
(defaults totrue
) it will prevent the request from firing immediately.It also provides a new function
execute
which can be used to trigger the request manually.Without this change,
useAsyncData
anduseFetch
need to be wrapped inside a function in order to call them on user interaction. With this change, no wrapping is necessary, and the request can be triggered manually viaexecute
, much like: https://vueuse.org/core/usefetch/#prevent-request-from-firing-immediatelyResolves nuxt/nuxt#14090
📝 Checklist