Replies: 1 comment
-
|
What i can do is probably to create a collection dynamically like so export const groupOrderSummaryCollection = (userId: string | undefined) => createCollection(
queryCollectionOptions({
queryKey: ["group_orders", "summary", userId],
queryFn: async () => getOrderByUser(userId),
enabled: Boolean(userId?.length),
getKey: (item) => item.id,
schema,
queryClient,
}),
);and then is my hooks that use the collections those collections would be created dynamically like these export function useGroupOrderSummary({ userId }: { userId: string }) {
return useLiveQuery(
(q) =>
q
.from({ gos: groupOrderSummaryCollection(userId) })
.where(({ gos }) => or(eq(gos.fromId, userId), eq(gos.toId, userId))),
[userId],
);
}But I'm not sure if this is the "correct" way to use the collections and/or if this would break caching |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
When working with Tanstack Query, it's very easy to write queries that depends on another query's input with correct execution flow by allowing passing undefined inputs (
userId: string | undefined) but then pause the query with theenabledoption.But with live queries, I don't see a way to pause the subsequent live queries or a way to use something akin to
skipTokento satisfy the typecheck. There IS anenabledoptions when you create a collection withqueryCollectionOptions, but that's on a collection creation level and not a hook level when you use it in arbitrary places in the code base. So my question is, with the below sample code how should i structure my live query props to have an order query only run when i have finished running my user query? appreciate the pointersBeta Was this translation helpful? Give feedback.
All reactions