tRPCttRPC
Powered by
manubaunM
tRPC•3y ago
manubaun

useSubscription simplified with react query

Hi Guys,

looking for a way to simplify the use of useSubscription. Currently I do the following:
1. create local state with the type of my subscription
2. call useSubscription, and pass onData to a setData

import type { UserSchema } from "@app/server/...";
// ...
    const [data, setData] = useState<UserSchema[]>([]);

    trpc.admin.users.all$.useSubscription(undefined, { onData: (d) => setData(d || []) });
import type { UserSchema } from "@app/server/...";
// ...
    const [data, setData] = useState<UserSchema[]>([]);

    trpc.admin.users.all$.useSubscription(undefined, { onData: (d) => setData(d || []) });



is there a way, to avoid it like I do? Then I would not need to
- import the types,
- create a local state,
- wiring up useSubscription and localState
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

Doubled subscriptions in React with useSubscription
Steve ASSteve A / ❓-help
11mo ago
Multi useSubscription with trpc react -query integration failed to find second sub
daizysDdaizys / ❓-help
3y ago
How to use querykeys from react-query
DR33MDDR33M / ❓-help
3y ago
CreateCaller with React-query
lunacraftsLlunacrafts / ❓-help
2y ago