A problem with UseQueryOptions type (lib version 5+) #6407
Unanswered
ValentinBond
asked this question in
Q&A
Replies: 2 comments 10 replies
-
please show at least a typescript playground. The general recommendation is to not pass type parameters to useQuery: https://tanstack.com/query/latest/docs/react/typescript#type-inference |
Beta Was this translation helpful? Give feedback.
0 replies
-
@ValentinBond Hey, did you solve your issue? I face the same problem, import { useQuery, type UseQueryOptions } from 'react-query';
function useCustomQueryHook (id: number, options?: UseQueryOptions<number>) {
return useQuery({
queryKey: ['custom', id],
queryFn: () => Promise.resolve(id),
...options,
});
}
useCustomQueryHook(5, {
// ts error: Property 'queryKey' is missing
staleTime: Infinity,
}); So what's the right way to pass additional options to custom hooks? @TkDodo |
Beta Was this translation helpful? Give feedback.
10 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
After upgrading the @tanstack/react-query package to version 5, I ran into a problem. I am using custom hooks like this:
const useUsersRetrieveQuery = <TSelect = UsersRetrieveType>({ ...options }: UseQueryOptions< UsersRetrieveType, ErrorType, TSelect> = {} ) => { return useQuery<UsersRetrieveType, ErrorType, TSelect>({ queryKey: [...], queryFn: usersRetrieve, ...options, }); };
and set queryKey inside that hook. Everything worked fine before, but now I get the error "Property queryKey is missing in type {} but required in type". I understand why this is happening. I just want to know the best way to use custom hooks with ts for queries.
Beta Was this translation helpful? Give feedback.
All reactions