T
TanStack2y ago
generous-apricot

How to access mutationState in v4? What is the pattern to work on project with many mutations?

I have a project where my entities have many states. State is changed by post requests. I have many post requests, that return current state or error of entity. I would like to have access to the data of post request in another component. So now i just setQueryData in onSuccess and onError. Is this right?
8 Replies
vicious-gold
vicious-gold2y ago
Yeah that’s nice
generous-apricot
generous-apricotOP2y ago
setQueryData is not updating state of another component. I do: onSuccess: (data) => { queryClient.setQueryData( [QUERY_KEY_REGISTERED_INVOICE, {barcode: data?.barcode}], data, ); }, but in another component getQueryData is not called again
No description
No description
generous-apricot
generous-apricotOP2y ago
I dont have GET method. So i just want to get updated data by key and rerender component, is it possible? ok, that somehow works without fetchFn
generous-apricot
generous-apricotOP2y ago
No description
generous-apricot
generous-apricotOP2y ago
I get errors in console: " Missing queryFn for queryKey '["registeredInvoice",{"barcode":"1110339131184383"}] " But i still get data and evrth works. Can i work with it? anyone?
vicious-gold
vicious-gold2y ago
Yea, provide some queryFn and set enabled: false
generous-apricot
generous-apricotOP2y ago
Ok, thank you for your answers. Do i understand right, that in v5 i can use useMutationState for that purpose more correctly?
vicious-gold
vicious-gold2y ago
Yeah that could work

Did you find this page helpful?