Skip to content
Discussion options

You must be logged in to vote

it's not the worst hack tbh, if you would store it on a ref / on a state variable. also, you can combine mutationKey and predicate to get rid of the JSON.stringify, as the predicate function is only called for already matching keys:

function useMutationData(mutationKey: unknown[]) {
  const [variables, setVariables] = React.useState()
  const isMutationInProgress = !!useIsMutating({
    mutationKey,
    predicate: ({ options }) => {
        setVariables(options.variables)
        return true
    },
  });
  return { isMutationInProgress, variables };
}

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 the queryCache ma…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@lgenzelis
Comment options

Answer selected by lgenzelis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants