Skip to content

How to implement abortController #300

Discussion options

You must be logged in to vote

I am happy to share I got it working by switching to onBeforeRouteLeave. This does raise the question when or why we need onUnmounted hook? 🤔 I still use that hook in a few components to remove keyboard event listeners. Perhaps I should consider moving these to the beforeUnmount hook to make sure they are actually removed as it seems I shouldn't trust my current method.

const client = useSanctumClient();
const abortController = new AbortController();

onBeforeRouteLeave(() => abortController.abort());

const { data } = await useAsyncData(() =>
  client('/example-endpoint', {
    signal: abortController.signal
  })
);

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@martijnhalekor
Comment options

@martijnhalekor
Comment options

Answer selected by martijnhalekor
@manchenkoff
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants