Is it possible to refetch a key on a button click? #5159
Unanswered
gmcamposano
asked this question in
Q&A
Replies: 1 comment 4 replies
-
Sorry to say that I don't understand the problem and it would be a lot easier with a running reproduction in e.g. codesandbox or stackblitz. |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This is relatively straight forward question which I think does not need an example -- as it will be hard to do for the following:
I have an invoice number in my app which is used in 3 different stores.. so when when 1 store saves that invoice number, the others should be able to print different invoice numbers.
What am i trying to do?
Whenever the user clicks on the print button, refetches the invoice_number key so that every stores always print the latest version of the invoice number
What is happening now?
It can happen that 2 stores end up printing the same invoice number because it the value changed in the backend but not in the frontend... so they printed the same number.
What I have tried:
I tried the
const getInvoice = useQuery({ queryKey: ["invoice_number"] })
and then rangetInoice.refetch()
whenever the print button is clicked - but did not workI also tried invalidating the query whenever the button is clicked - but it doesnt do anything.
Beta Was this translation helpful? Give feedback.
All reactions