我在 React 本机组件中使用下面的 @apollo/GraphQL 查询
const [getContent, {
error, data, fetchMore, called
}] = useLazyQuery(BROWSE_CONTENT, {
variables: {
sessionIdToken: sessionId,
deviceLocale,
paginationCursor: `'${payload.endCursor}'`
}
})
一旦我有了数据,我就使用 RecyclerListView 来呈现列表。
问题:由于它的异步调用(useLazyQuery),所以如果用户快速更改视图(通过单击按钮),我会遇到以下错误。
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)
如何在组件卸载时取消 useLazyQuery。