T
TanStack2y ago
stormy-gold

UseQueryOptions without providing a required `queryKey`

hello, is there a way to use UseQueryOptions without providing a required queryKey? im upgrading to v5 and in v4 this was never required. I am using a custom hook with react query
export const useCustomHook = (id: string, options?: UseQueryOptions<Group>) => {
const { profile } = useAuth();

return useQuery({
queryKey: ...,
queryFn: () => ...,
...options
});
};

useCustomHook(id, {
enabled: ... // queryKey is required here but I dont want to pass it
})
export const useCustomHook = (id: string, options?: UseQueryOptions<Group>) => {
const { profile } = useAuth();

return useQuery({
queryKey: ...,
queryFn: () => ...,
...options
});
};

useCustomHook(id, {
enabled: ... // queryKey is required here but I dont want to pass it
})
3 Replies
wise-white
wise-white2y ago
Omit<UseQueryOptions<Group>, 'queryKey'> but my advice is to not allow passing all options in, only the ones you really need. enabled is just a boolean so enabled: boolean will do UseQueryOptions actually has 4 generics so you might get into other issues with that approach
stormy-gold
stormy-goldOP2y ago
yeah I ended up using Omit thanks 1 more quick question, we can just keep the optimistic updates as in 4 right? no need to change to the v5 ""way"? as in onMutate, onError etc
wise-white
wise-white2y ago
yes

Did you find this page helpful?