artistrea
artistrea
TtRPC
Created by Vilian on 8/4/2024 in #❓-help
How to query with async/await
And if you really need to use zustand with react query this way, I think you will need to use mutations
12 replies
TtRPC
Created by Vilian on 8/4/2024 in #❓-help
How to query with async/await
I'm actually not sure what is the syntax for some of the code above, so it may not work out of the box
12 replies
TtRPC
Created by Vilian on 8/4/2024 in #❓-help
How to query with async/await
// since react query shares data globally, this hook works like a store
export function useSomeData() {
const usersQuery = api.users.all.useQuery();

const reloadUsers = api.users.all.refetch;

return {
users: usersQuery.data,
reloadUsers,
reset: async () => {
api.users.all.setQueryData(null);
api.users.all.invalidateQuery();
// ...
}
}
}
// since react query shares data globally, this hook works like a store
export function useSomeData() {
const usersQuery = api.users.all.useQuery();

const reloadUsers = api.users.all.refetch;

return {
users: usersQuery.data,
reloadUsers,
reset: async () => {
api.users.all.setQueryData(null);
api.users.all.invalidateQuery();
// ...
}
}
}
12 replies
TtRPC
Created by Vilian on 8/4/2024 in #❓-help
How to query with async/await
I'm not sure if I didn't understand some requirement, but I would do something like this:
12 replies
TtRPC
Created by Vilian on 8/4/2024 in #❓-help
How to query with async/await
Why would you use zustand when react query already caches data, dedupes requests and has primitives to interact with the data?
12 replies
TtRPC
Created by Billy Swedish on 8/4/2024 in #❓-help
tRPC and playing audio files on the frontend
Unless you already got a system like s3 to generate presigned/download urls, then your server just has to send the url for the client to download, and that can be done easily in trpc.
4 replies
TtRPC
Created by Billy Swedish on 8/4/2024 in #❓-help
tRPC and playing audio files on the frontend
It's been some time since I last used trpc, but https://trpc.io/docs/rpc#http-response-specification I don't think tRPC wants to support that at all. They are different comm systems, and trying to stream files through a spec that only makes it more difficult to do so is like asking for bugs. You should probably serve the trpc endpoints with express https://trpc.io/docs/server/adapters/express And just make an endpoint that streams the file
4 replies
TtRPC
Created by funki on 6/21/2024 in #❓-help
Why are `new QueryClient` and `trpc.createClient` run inside a component in the React setup?
I didn't think that would be there lol
25 replies
TtRPC
Created by funki on 6/21/2024 in #❓-help
Why are `new QueryClient` and `trpc.createClient` run inside a component in the React setup?
No description
25 replies
TtRPC
Created by funki on 6/21/2024 in #❓-help
Why are `new QueryClient` and `trpc.createClient` run inside a component in the React setup?
just now I opened the docs you linked*
25 replies
TtRPC
Created by funki on 6/21/2024 in #❓-help
Why are `new QueryClient` and `trpc.createClient` run inside a component in the React setup?
I mean
25 replies
TtRPC
Created by funki on 6/21/2024 in #❓-help
Why are `new QueryClient` and `trpc.createClient` run inside a component in the React setup?
Not sure about this though
25 replies
TtRPC
Created by funki on 6/21/2024 in #❓-help
Why are `new QueryClient` and `trpc.createClient` run inside a component in the React setup?
But I think the requests also wouldn't be deduped on the server as well
25 replies
TtRPC
Created by funki on 6/21/2024 in #❓-help
Why are `new QueryClient` and `trpc.createClient` run inside a component in the React setup?
And you could
25 replies
TtRPC
Created by funki on 6/21/2024 in #❓-help
Why are `new QueryClient` and `trpc.createClient` run inside a component in the React setup?
I agree
25 replies
TtRPC
Created by funki on 6/21/2024 in #❓-help
Why are `new QueryClient` and `trpc.createClient` run inside a component in the React setup?
You don't want it to share cache between different requests, which can be from different users
25 replies
TtRPC
Created by funki on 6/21/2024 in #❓-help
Why are `new QueryClient` and `trpc.createClient` run inside a component in the React setup?
It stores the api calls in cache
25 replies
TtRPC
Created by funki on 6/21/2024 in #❓-help
Why are `new QueryClient` and `trpc.createClient` run inside a component in the React setup?
Basically, the query client is stateful
25 replies
TtRPC
Created by funki on 6/21/2024 in #❓-help
Why are `new QueryClient` and `trpc.createClient` run inside a component in the React setup?
The reason is ssr
25 replies
TtRPC
Created by funki on 6/21/2024 in #❓-help
Why are `new QueryClient` and `trpc.createClient` run inside a component in the React setup?
This is not related to trpc, the example is an example using react query
25 replies