T
TanStack•3y ago
fascinating-indigo

Get loading in useMutation v5 beta

Hello, how do I get the current state of mutation like isLoading? It looks like missing on v5 beta? Or did I miss something? Thank you. In addition to this. How can I get access to the current state of mutation? Since my action button was located from the other component. Like, I want to disable it if the request still processing (from other REST API)
6 Replies
helpful-purple
helpful-purple•3y ago
Alpha or beta? And status is still in MutationObserverResult
conscious-sapphire
conscious-sapphire•3y ago
isLoading was renamed to isPending, it's still there. to get the status of a running mutation in a different component, you can use useMutationState - a new hook in v5: https://tanstack.com/query/v5/docs/react/reference/useMutationState
useMutationState | TanStack Query Docs
useMutationState is a hook that gives you access to all mutations in the MutationCache. You can pass filters to it to narrow down your mutations, and select to transform the mutation state. `tsx
fascinating-indigo
fascinating-indigoOP•3y ago
Thanks for reply. I actually using beta. Just edit it to beta Thanks as always Dom. 😇
fascinating-indigo
fascinating-indigoOP•3y ago
Good day @TkDodo 🔮. In relation to my concern above, I have another question though. For reference, I've included a screenshot. In all honesty, I'm not sure if what I'm observing is consistent with the behavior of the mutation state. The "First image" gives me a correct result as anticipated when I fire the first mutation and the promise resolves. On the same process, I attempted to reject the mutation based on the specified criteria in the code, though. The result of the mutation state is incorrect. As I keep firing both Promise resolve and Reject, the message in "(Second Image)" appears. Technically, my issue was the useMutationState status is not giving proper value. My observation was when I fire a mutation again it will not go back to pending state again. Whichever the previous status would be that's what is returning. Thank you for your usual support.
No description
conscious-sapphire
conscious-sapphire•3y ago
hmm could be a bug with useMutationState. Can you do a sandbox reproduction?
fascinating-indigo
fascinating-indigoOP•3y ago
Apologise for the late reply. Sure, when I get back to my desk. Thank you again dom.

Did you find this page helpful?