4

I'm trying to use react guery to get some sata from this funcktion.

export const quotaReservationRefundServiceBankAccount = (
  id: string,
  bankAccountInformation: IBankAccountInformation,
  quotaLegal?: string,
): Promise<Response> => {
  const url = `${appSettings.bffUrl}/api/pregnancies/quotareservations/${id}/bankaccount/refund`;
  const body: IRefundQuotaReservationRequest = {
    language: appSettings.language,
    bankAccountInformation,
    legalDepartmentShortCode: quotaLegal || "",
  };
  return post(url, body);
};

I have gotten this fare:

  const { data: testData, isLoading, error } = useQuery<string, IBankAccountInformation, string | undefined>(["bankRefundResponse",  quota?.reservation || "Quota.reservation missing", bankAccountInfo, quota.legal], quotaReservationRefundServiceBankAccount, {

      });

Typescript gives me this error:

Argument of type '(id: string, bankAccountInformation: IBankAccountInformation, quotaLegal?: string | undefined) => Promise' is not assignable to parameter of type 'QueryFunction<string, QueryKey>'.ts(2345)

1 Answer 1

8

parameters are passed to the queryFn via the queryKey, so you can either destruct the queryKey (first argument to the queryFn) or just use an inline function:

useQuery(["key", id, bankAccountInformation, quota], () => quotaReservationRefundServiceBankAccount(id, bankAccountInformation, quota))
Sign up to request clarification or add additional context in comments.

8 Comments

It gives me this error: Type 'Promise<Response>' is not assignable to type 'string | Promise<string>'. Type 'Promise<Response>' is not assignable to type 'Promise<string>'. Type 'Response' is not assignable to type 'string'.ts(2322) types.d.ts(7, 89): The expected type comes from the return type of this signature.
Likely because quotaReservationRefundServiceBankAccount returns Promise<Response>, but you've typed useQuery<string>. Have you tried useQuery without annotating the generics like in my example above?
Looks like it works. How would I then get the data after the promise. I need to json() the response I guess.
this should most likely happen in quotaReservationRefundServiceBankAccount. return post(url, body).then(response=> response.json());
What do you do if one af the parameters could be undefined. Can you then stop the query? Now that you can not rap react-query in a condition.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.