useAbortController
Atomico now introduces a new hook called useAbortController, which allows aborting the execution of asynchronous calls, example:
Example
import { useAsync, useAbortController } from 'atomico';
async function getUser(id: number, signal: AbortSignal) {
return fetch(`/id/${id}`, { signal });
}
function myComponent({ userId }: Props<typeof myComponent>) {
const { signal } = useAbortController([userId]);
const user = useAsync(getUser, [userId, signal]);
return <host>{user.name}</host>;
}
myComponent.props = { userId: { type: Number, value: 0 } };Last updated
Was this helpful?
