Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use $fetch instead of useAsyncData #66

Closed
ozum opened this issue Jan 18, 2023 · 2 comments
Closed

How to use $fetch instead of useAsyncData #66

ozum opened this issue Jan 18, 2023 · 2 comments

Comments

@ozum
Copy link

ozum commented Jan 18, 2023

Hi @wobsoriano,

useQuery()  leverages useAsyncData which is great for most use cases. However, I need raw data, because I use vue-query.

The front page of the documentation site states that we can also use $fetch. How can I use $fetch instead of useAsyncData?

For example:

const fetcher = () => $client.hello.useQuery({ text: "client" });

const { isLoading, isError, data, error } = useQuery({ queryKey: ["test"], queryFn: fetcher });

I can use $client.hello.query({ text: "client" }) instead of useQuery, but I want to leverage $fetch.

Many thanks,

@qin-guan
Copy link

Hey @ozum, not sure if you’ve resolved this yet.

I believe you’re able to use .query(…) instead of .useQuery(…) which should give you access to the raw query without useAsyncData.

It is outlined in the docs here https://trpc-nuxt.vercel.app/get-started/client

@wobsoriano
Copy link
Owner

Thanks @qin-guan!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants