manubaun
manubaun13mo ago

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
0 Replies
No replies yetBe the first to reply to this messageJoin