Home > Net >  rect-query: Pass additional key for navigation
rect-query: Pass additional key for navigation

Time:09-30

I am trying to pass a key for navigation, which specifies to show the query/page after the current query call.

useform.ts

...
...

export const useupdateSurveyForm = () => {
  const queryClient = useQueryClient();
  return useMutation({
    mutationFn: updateSurveyForm,
    onSuccess: (data) => {
      queryClient.invalidateQueries(["searched-public-survey"]);
    },
  });
};

here added "invalidateQueries(["searched-public-survey"]" directly then the code is working properly, but I want to make this dynamic. like,

queryClient.invalidateQueries(navigationqueryKey);

For that I made some changes

plans.ts

...
...
  const {
    mutate: updateArchiveSurveyStatus,
    navigationqueryKey: "searched-public-survey",
  } = useupdateSurveyForm();

...
...

pass "navigationKey: "searched-public-survey", but it shows an error

Property 'searched-public-survey' does not exist on type 'UseMutationResult<any, unknown, SurveyUpdatePayload, unknown>'.

Give me some solution to fix this problem.

CodePudding user response:

I dont know if it is correct to pass the value for the query that way.

The statement from the plain.ts is just the return value. I did not found anything in the docs which would lead to putting in the navigation query key.

If I get you correctly I think what you want to do would look like:

export const useupdateSurveyForm = (key: string) => {
  const queryClient = useQueryClient();
  return useMutation({
    mutationFn: updateSurveyForm,
    onSuccess: (data) => {
      queryClient.invalidateQueries([key]);
    },
  });
};

And the plans.ts would then look like:

  const {
    mutate: updateArchiveSurveyStatus,
  } = useupdateSurveyForm("searched-public-survey");

Maybe that helps. :-)

  • Related