#UseQueryOptions without providing a required `queryKey`

8 messages · Page 1 of 1 (latest)

unborn galleon
#

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
})
fair marten
#

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

unborn galleon
#

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