有没有办法使用@apollo/react-hooks访问多个graphql突变的选项

Is there a way to access options for multiple graphql mutations with @apollo/react-hooks

我有一个包含两次数据的多部分表单。我在我的组件中使用了两个突变,所以它看起来像这样。

const [register, { loading }] = useMutation(REGISTER),
      [tags, { loading }] = useMutation(TAGS);

这显然行不通,因为我不能有两个加载变量。我一直在尝试为该场景找到解决方法,但没有成功。

如果这是一个查询,我知道我可以这样做:

const register = useQuery(REGISTER),
      tags = useQuery(TAGS);

// now I have register.loading && tags.loading

但我还没有找到与 useMutation 类似的情况,因为如果我有类似的东西:

const register = useMutation(REGISTER);

register({var: "something"})
  .then(res => {  });

然后就没有 promise 并且会抛出错误。

是否有处理此类实例的更好做法?

您可以在解构时简单地重命名变量(参考: https://wesbos.com/destructuring-renaming/)

因此您的代码将如下所示:

const [register, { loading: registerLoading }] = useMutation(REGISTER),
const [tags, { loading: tagsLoading }] = useMutation(TAGS);