0

ApolloGraphqQL 在使用useQueryhook 时提供了 2 种轮询数据的方法。

一种方法使用钩子返回的startPollingandstopPolling函数useQuery,当组件像这样卸载时,我调用 stopPolling:

const { loading, error, data, startPolling, stopPolling } = useQuery(GET_DOG_PHOTO, {
    variables: { breed },
  });

/* elsewhere in the component */

useEffect(() => {
   startPolling(2000); //poll every 2 seconds
   return stopPolling; //cleanup, when component unmounts
},[])

但是,如果我执行以下操作,在这种情况下是否还需要通过调用 stopPolling 来清理此处的轮询?

const { loading, error, data } = useQuery(GET_DOG_PHOTO, {
    variables: { breed },
    pollInterval: 500,
  });
4

0 回答 0