TanStackT
TanStack12mo ago
4 replies
foolish-indigo

What would be the correct way to type queryKey if input is a skipToken?

export const useGetProjectQueryKey = (variables: GetProjectRequest) => [
  "projects",
  variables.params.pid,
];

export const useGetProjectQuery = <TData = Project>(
  variables: GetProjectRequest | SkipToken,
  {
    ...options
  }: Omit<
    UseQueryOptions<Project, Error | ZodError, TData>,
    "queryKey" | "queryFn"
  > = {},
) =>
  useQuery<Project, Error | ZodError, TData>({
    queryKey: variables === skipToken ? [] : useGetProjectQueryKey(variables),
    queryFn: variables === skipToken ? skipToken : ({ signal }) => getProject(variables, signal),
    ...options,
  });


If
queryFn
is a skipToken would it ignore the queryKey? If it does would an empty array suffice?
Was this page helpful?