TanStackT
TanStack16mo ago
5 replies
urgent-maroon

useQueries & queryOptions typing issue

Anyone else running into issue with code similar to:

const queries = [
  getOptions1(
    queryDetails[0],
    question,
  ),
  getOptions2(
    queryDetails[1],
    question,
  ),
];

const { data } = useQueries({
  queries,
  ...


const getOptions1 = (
  queryDetails: MyInterface,
  question: string,
) => {
    return queryOptions({
      queryKey: ['source1', queryDetails, question],
      queryFn: () =>
        service.getDetails({
          question,
        }),
      retry: false,
      refetchOnWindowFocus: false,
    });
};


const getOptions2 = (
  queryDetails: MyInterface,
  question: string,
) => {
    return queryOptions({
      queryKey: ['source2', queryDetails, question],
      queryFn: () =>
        anotherService.getDetails({
          question,
        }),
      retry: false,
      refetchOnWindowFocus: false,
    });
};


I am getting: The type QueryKey is readonly and cannot be assigned to the mutable type

When I only use the result of getOptions1 (single item in an array) or remove queryOptions it does work, not sure what I am doing wrong.
Was this page helpful?