0

In one file, I have

export const useAlertMachine = () => {
  const updateAlertsMutation = useUpdateAlerts();
  return {
    updateAlertsMutation
  };
};

updateAlertsMutation has states isLoading, isSuccess, isIdle, and isError. I want to be able to access these states in another file. For example,

import {useAlertMachine} from '+/machines/alertMachine'
const Alert = () => {
  const {updateAlertsMutation} = useAlertMachine();
  // want to access updateAlertsMutation.isLoading here, referring to the mutation defined in the first file
}

Right now, each instance of updateAlertsMutation is independent - is it possible to access its state across files?

Collin Sinclair
  • 453
  • 1
  • 3
  • 12
  • I think the best way is to use context or pass it up in the tree to the parent component, but it seems like there is a hack: https://tanstack.com/query/v4/docs/guides/mutations#persist-mutations, I do not know if your use case was the original intention of this feature, but... if you really want seems like you can use it. – Nevo Sep 30 '22 at 22:58

1 Answers1

0

Not right now, no. There is an open issue, but it's unlikely that we will focus on this in the near future.

TkDodo
  • 20,449
  • 3
  • 50
  • 65