プロシージャ呼び出しの中断
非公式ベータ版翻訳
このページは PageTurner AI で翻訳されました(ベータ版)。プロジェクト公式の承認はありません。 エラーを見つけましたか? 問題を報告 →
tRPCはプロシージャを中断するための標準的なAbortController/AbortSignal APIをサポートしています。必要なのは、クエリやミューテーションのオプションにAbortSignalを渡すことだけです。そして、リクエストをキャンセルする必要がある場合には、AbortControllerインスタンスのabortメソッドを呼び出します。
utils.tstsimport {createTRPCClient ,httpBatchLink } from '@trpc/client';import type {AppRouter } from './server';constclient =createTRPCClient <AppRouter >({links : [httpBatchLink ({url : 'http://localhost:3000/trpc',}),],});// 1. Create an AbortController instance - this is a standard javascript APIconstac = newAbortController ();// 2. Pass the signal to a query or mutationconstquery =client .userById .query ('id_bilbo', {signal :ac .signal });// 3. Cancel the request if neededac .abort ();
utils.tstsimport {createTRPCClient ,httpBatchLink } from '@trpc/client';import type {AppRouter } from './server';constclient =createTRPCClient <AppRouter >({links : [httpBatchLink ({url : 'http://localhost:3000/trpc',}),],});// 1. Create an AbortController instance - this is a standard javascript APIconstac = newAbortController ();// 2. Pass the signal to a query or mutationconstquery =client .userById .query ('id_bilbo', {signal :ac .signal });// 3. Cancel the request if neededac .abort ();