-
I know I can do this: Also, currently we have a Currently, I'm doing a very hacky thing to access those variables, so, if there is an official way to do it, I'd love to know about it 🙂 : function useMutationData(mutationKey: unknown[]) {
let ongoingMutationVariables: unknown;
const isMutationInProgress = !!useIsMutating({
predicate: ({ options }) => {
if (JSON.stringify(options.mutationKey) === JSON.stringify(mutationKey)) {
ongoingMutationVariables = options.variables;
return true;
}
return false;
},
});
return { isMutationInProgress, ongoingMutationVariables };
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
it's not the worst hack tbh, if you would store it on a ref / on a state variable. also, you can combine
but yes, it's a bit weird to use the setting state is easier if that state is referentially stable, like a number. If you |
Beta Was this translation helpful? Give feedback.
it's not the worst hack tbh, if you would store it on a ref / on a state variable. also, you can combine
mutationKey
andpredicate
to get rid of theJSON.stringify
, as thepredicate
function is only called for already matching keys:but yes, it's a bit weird to use the
predicate
function to store a side-effect. You can of course also just subscribe to thequeryCache
ma…