DEV Community

Cover image for React Apollo: useQuery pollInterval with cache-and-network doesn't stop to make requests after unmounting the component
SeongKuk Han
SeongKuk Han

Posted on

React Apollo: useQuery pollInterval with cache-and-network doesn't stop to make requests after unmounting the component

I've made the issue here in apollo-client repository.

It works well with other fetchPolicy options but it doens't work correctly with cache-and-network.

Before resolving the issue, here is one of the alternatives.

alternative

Starting polling manually

const {
    data: todosData,
    error,
    startPolling,
    stopPolling,
  } = useQuery(GET_TODOS, {
    fetchPolicy: "cache-and-network",
  });

  useEffect(() => {
    startPolling(1000); // poll interval

    return () => {
      stopPolling();
    };
  }, []);
Enter fullscreen mode Exit fullscreen mode

Top comments (0)