#How to share useMutation() return value across components?

5 messages · Page 1 of 1 (latest)

hollow pollen
#

Hi guys, I'm just starting out with TSQ!

I have a component that's calling useMutation. However, I want to access its return value (specifically .isPending and .variables) in a faraway component. Is this achievable without prop-drilling or a custom context? Thanks 🙂

meager dust
#

With useMutationState

hollow pollen
#

Hi there!

I looked into this!

I want to check if a specific mutation call is pending and get that specific calls variables.

However, since useMutationState returns an array, I end up getting an array of each mutation.state for each of the calls.

This leaves me no way to identify the specific mutation.state that I want to read from. Any ideas?

I have thought that perhaps after each mutation call succeeds, I could clear that particular mutation cache, meaning that useMutationState() will theoretically always return an array of length 1.

Any help is appreciated! 🙂

latent phoenix
#

Give the mutation a mutationKey and filter by that key when calling useMutationState.