Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

rect-query: Pass additional key for navigation

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,

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

>Solution :

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. 🙂

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading