falcondev-oss / trpc-vue-query

Fully type-safe composables and helpers to make working with tRPC + Tanstack Query as intuitive as possible.
https://trpc-vue-query.falcondev.io
MIT License
17 stars 1 forks source link

Uncaught Error: vue-query hooks can only be used inside setup() function or functions that support injection context #3

Closed NiciusB closed 7 months ago

NiciusB commented 7 months ago

When following the instructions in your README it fails with the error on the title

The solution I found was to wrap it inside app.runWithContext:

  install(app) {
      const queryClient = app.runWithContext(useQueryClient)

      const trpcVueQuery = createTRPCVueQueryClient<AppRouter>({
        queryClient,
        trpc: {
          links: [serverLink],
        },
      })
      app.provide("trpc", trpcVueQuery)
  },
LouisHaftmann commented 7 months ago

Thanks for reporting this issue! I updated the README. We are also currently working on a full documentation page.