React JS / Apollo Client - How to cancel/stop a useLazyQuery when user leave component?

Viewed 47

I am using useLazyQuery function and I don't know how to cancel/stop the request when user leave the component.

This is my code:

  const [getPosts] = useLazyQuery(GET_POSTS);

  useEffect(() => {
    
    fetchPosts();

    return () => {
      // Leave component: How stop the request
      
    }

  }, []);

Thank
Best Regard

0 Answers
Related