【发布时间】:2021-09-17 16:46:47
【问题描述】:
使用 React 和 Apollo React 钩子
import { useCallback, useState } from "react";
import { useMutation, useSubscription, useQuery } from "@apollo/react-hooks";
我得到了一个函数useChannel,其中我的所有graphql 突变都有钩子。
每个突变都被导入,然后声明为常量,如下所示:
const [addExportChannel] = useMutation(AddExportChannelMutation);
我像这样在钩子的返回函数中使用它
const onAddImportChannel = useCallback(
async (props) => {
try {
const data = await addImportChannel({
variables: {
shopId,
name: props.name,
url: props.url,
filetype: props.filetype
}
});
...
当我尝试对 useQuery 执行相同操作时,它会说 useQuery 不可迭代。
TypeError: useQuery is not a function or its return value is not iterable
const [FeedProcess] = useQuery(GetFeedProcessQuery);
...
const onFeedProcess = useCallback(
async (props) => {
try {
const data = await FeedProcess({
variables: { shopId, feedId: props.feedId }
});
...
我在这里遗漏了什么,试图弄清楚这两个钩子有什么不同。
【问题讨论】:
标签: reactjs react-hooks apollo react-apollo