【问题标题】:Can I access the state of a React Query mutation across files?我可以跨文件访问 React Query 突变的状态吗?
【发布时间】:2022-10-07 16:12:23
【问题描述】:

在一个文件中,我有

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

updateAlertsMutationhas statesisLoadingisSuccessisIdleisError。我希望能够在另一个文件中访问这些状态。例如,

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
}

现在,updateAlertsMutation 的每个实例都是独立的——是否可以跨文件访问其状态?

【问题讨论】:

标签: javascript reactjs react-query xstate


【解决方案1】:

现在不行,不行。有an open issue,但我们不太可能在不久的将来专注于此。

【讨论】:

    猜你喜欢
    • 2016-01-02
    • 1970-01-01
    • 2010-09-21
    • 2021-12-30
    • 1970-01-01
    • 2019-04-12
    • 1970-01-01
    • 2018-02-17
    • 1970-01-01
    相关资源
    最近更新 更多