Usage from within a Vue plugin
I am looking to create a Vue plugin that needs to be able to access the cache and refetch if necessary. Is this even possible considering useQuery can only be used in a setup function?
4 Replies
adverse-sapphire•3y ago
It's possible. You have to create QueryClient manually and then pass it to both your pluging and VueQueryPlugin as an option.
Notice that with this solution you might sometimes experience weirdness when HMR updates modules.
deep-jadeOP•3y ago
Thanks for the response! Sorry I've looked through the docs on QueryClient and I don't quite understand your solution. Is there an example of this in the docs? Or would you mind providing a small code sample of how this might look?
adverse-sapphire•3y ago
https://github.com/TanStack/query/blob/main/docs/vue/guides/custom-client.md
Not sure why it's not hooked up to the docs though 😄
deep-jadeOP•3y ago
Thats great. Thanks!