Replies: 1 comment
-
This is a limitation of Pinia, unfortunately. Pinia is meant to be scoped globally, and isn't really meant to be tied to a component lifecycle. However, after doing some digging, I noticed that they did add a $dispose function to the store: You could probably create a pair of composables and leverage provide/inject to fully scope a store to a component subtree and tie it to the root's lifecycle. Note that I haven't tried this yet, but this seems possible.
There's a possibility you might have to manually clean up state. Unsure about that. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
If we use
useQuery
inside pinia store to fetch data that is then used inside getters for example, useQuery still sends requests after we leave the page and the data is no longer used.Is there a good way to prevent this from happening? Maybe there are guidelines on how to use data that is fetched by tanstack query inside pinia store?
Here is a small reproduction https://stackblitz.com/edit/vue3-vite-router-typescript-starter-1pyp7c?file=src%2FcounterStore.ts
when useQuery is used in a component the request wouldn't be refetched like it does when it's used in pinia. For example here i wouldn't expect on the About page that the request is sent:
Screen.Recording.2024-06-17.at.16.32.52.mov
Beta Was this translation helpful? Give feedback.
All reactions