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

1 1

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)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay