manubaunM
tRPC3y 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 || []) });



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
Was this page helpful?