T
TanStack3y ago
fascinating-indigo

Is there a way to set a types for queryClient without casting everytime?

Hello, I have a custom useQuery hook:
export function useGetChannels(userId: string | undefined) {
return useQuery({
queryKey: ["channels"],
queryFn: () => fetchChannels({ userId, pageParam: 0 }),
enabled: !!userId,
});
}
export function useGetChannels(userId: string | undefined) {
return useQuery({
queryKey: ["channels"],
queryFn: () => fetchChannels({ userId, pageParam: 0 }),
enabled: !!userId,
});
}
I want to access this query using queryClient, but the type is unknown:
const channelsQueryData = queryClient.getQueryData(["channels"]);
const channelsQueryData = queryClient.getQueryData(["channels"]);
is there a way for me to set the types for channels, so that I will be able to access it without having to cast it evertytime i use the getQueryData or setQueryData?
1 Reply
variable-lime
variable-lime3y ago
nope, you need querClient.getQueryData<Channels>["channels"] but out of curiosity: why do you need getQueryData , apart from optimstic updates ?

Did you find this page helpful?