TaskContext
What a task's or resource's work receives first: the signal that aborts it when it is cancelled or replaced.
Usage
Cancel a request with its task.
// Cancel a request with its task.
import { Button, Text, task, type TaskContext } from 'kuito';
// The signal aborts the request when the task is cancelled or replaced.
async function search({ signal }: TaskContext, term: string): Promise<string[]> {
const response = await fetch(`https://api.example.com/search?q=${encodeURIComponent(term)}`, {
signal,
});
return (await response.json()) as string[];
}
function Search() {
const results = task(search);
return (
<>
<Button onPress={() => results.run('kuito')}>Search</Button>
<Text>{results.data.value?.length ?? 0} results</Text>
</>
);
}Type declaration
export interface TaskContext {
readonly signal: AbortSignal;
}Members 1
| Name | Type | Required | Description |
|---|---|---|---|
signalreadonly | AbortSignal | Yes | — |
Generated from the public TypeScript declarations: signatures, props and defaults come from the checked source, descriptions from its JSDoc. No defaults are invented.