T
TanStack3y ago
dependent-tan

Is there a way to unsubscribe from a query (prefetching advice)?

I have a composable that looks like this - I need everything in table when using this composable but it is making prefetch quite difficult. Is there a way I can do something like calling useParticipantsTable in a parent component (which would prefetch) but then unsubscribe from the query?
export const useParticipantsTable = () => {
const table = useServerTable({
// ...
});

const { data } = useQuery({
queryKey: ["participants", "list", table],
queryFn: () => {
return participantsClient.getParticipants({
...table.queryOptions.value,
});
},
keepPreviousData: true,
});


return {
data,
};
};
export const useParticipantsTable = () => {
const table = useServerTable({
// ...
});

const { data } = useQuery({
queryKey: ["participants", "list", table],
queryFn: () => {
return participantsClient.getParticipants({
...table.queryOptions.value,
});
},
keepPreviousData: true,
});


return {
data,
};
};
1 Reply
dependent-tan
dependent-tanOP3y ago
Or is there a better way to define this to make prefetching easier? table is quite a complicated object so I can just recreate it from scratch to prefetch

Did you find this page helpful?