Guides & concepts
Cancellation and timeouts
Including outside React.
// A signal you control
const controller = new AbortController();
await ep.fetch(undefined, { signal: controller.signal });
// A timeout, per call
await ep.fetch({ page: 1 }, { timeout: 5_000 });
// Or as an endpoint default
const impatient = ep.withOptions({ timeout: 5_000 });A per-call timeout overrides an endpoint default. Signals compose rather than replace: if you pass a signal and a timeout, whichever fires first wins.
Why not a promise race
Timeouts are built on AbortSignal.timeout. Racing a timer against the request promise settles your promise but leaves the real request running, holding a connection-pool slot — about six per host in Chrome — until the server eventually answers.
Mutations
Opt in with cancelOnUnmount, and call abort() on the result to stop the attempt in flight.
const save = api.users.update
.withOptions({ cancelOnUnmount: true })
.useMutation();
save.mutate({ name: 'Ada' });
save.abort();