Understanding conesequences of using useQuery inside of pinia store. #7909
Unanswered
cory-weiner
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm looking at implementing tanstack into a new Vue 3 project. For most use cases in my app, I am planning to implement useQuery directly in the components, however I have a few pages which are more complex, where I'd like the async state to be shared among a dozen or so components, along with some shared computed properties, methods, etc.
For example, I have a "schedule" page, which fetches a list of events. My initial thought was to create a pinia store, where useQuery is used inside of the store.
However, I'm wondering what the effect of that will be on garbage collection of the query? And if there are other consequences of using useQuery in this manner? In theory, once they leave the specific "schedule" page of the app, I'd like the query to be garbage collected as normal (I believe 5 minutes is the default).
Am I on the right path here? Is there a better approach? I am also thinking you could use some kind of composable that tracks onMounted and onUnmounted lifecycle to know if any items are left, and if so delete the shared reference. I also found this Vue API effectScope which could be useful:
https://vuejs.org/api/reactivity-advanced.html#effectscope
Beta Was this translation helpful? Give feedback.
All reactions