T
TanStack15mo ago
adverse-sapphire

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
yelping-magenta
yelping-magenta15mo ago
Yeah that’s nice
adverse-sapphire
adverse-sapphireOP15mo 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
adverse-sapphire
adverse-sapphireOP15mo 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
adverse-sapphire
adverse-sapphireOP15mo ago
No description
adverse-sapphire
adverse-sapphireOP15mo 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?
yelping-magenta
yelping-magenta15mo ago
Yea, provide some queryFn and set enabled: false
adverse-sapphire
adverse-sapphireOP15mo ago
Ok, thank you for your answers. Do i understand right, that in v5 i can use useMutationState for that purpose more correctly?
yelping-magenta
yelping-magenta15mo ago
Yeah that could work

Did you find this page helpful?