Cancel graphQL call on component unmount

Viewed 591

I am using below @apollo/GraphQL query inside a React native component

const [getContent, {
    error, data, fetchMore, called
  }] = useLazyQuery(BROWSE_CONTENT, {
    variables: {
      sessionIdToken: sessionId,
      deviceLocale,
      paginationCursor: `'${payload.endCursor}'`
    }
  })

Once i have data, I use RecyclerListView to render the list.

Problem: since its async call (useLazyQuery), so if user quickly change the View (by clicking the button) i am getting below error.

Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.
    in RecyclerListView (at MyComponent.js:345)

How to cancel useLazyQuery on component unmount.

0 Answers
Related