onAbort
since v0.12
Binds a passed function to the aborting of the Query or Mutation.
ts
import { onAbort, createQuery } from '@farfetched/core';
const myQuery = createQuery({
async handler() {
const abortController = new AbortController();
onAbort(() => {
abortController.abort();
});
const response = await fetch('https://example.com', {
signal: abortController.signal,
});
return response.text();
},
});
Limitations
onAbort
can only be called inside the handler of a Query or Mutation. Calling it outside a handler will throw an error.onAbort
can only be called once per handler. Calling it multiple times will throw an error.onAbort
can only be called before asynchronous operations are started. Calling it after asynchronous operations have started will throw an error.