manubaun
manubaun
Explore posts from servers
TtRPC
Created by manubaun on 7/17/2023 in #❓-help
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
1 replies