Cancelación de llamadas a procedimientos
Traducción Beta No Oficial
Esta página fue traducida por PageTurner AI (beta). No está respaldada oficialmente por el proyecto. ¿Encontraste un error? Reportar problema →
Por defecto, tRPC no cancela las solicitudes al desmontar componentes. Si deseas habilitar este comportamiento, puedes incluir abortOnUnmount en tu callback de configuración.
Globalmente
client.tstsimport {httpBatchLink } from '@trpc/client';import {createTRPCNext } from '@trpc/next';import type {AppRouter } from './server/routers/_app';export consttrpc =createTRPCNext <AppRouter >({config () {return {links : [httpBatchLink ({url : '/api/trpc',}),],abortOnUnmount : true,};},});
client.tstsimport {httpBatchLink } from '@trpc/client';import {createTRPCNext } from '@trpc/next';import type {AppRouter } from './server/routers/_app';export consttrpc =createTRPCNext <AppRouter >({config () {return {links : [httpBatchLink ({url : '/api/trpc',}),],abortOnUnmount : true,};},});
Por solicitud
También puedes sobrescribir este comportamiento a nivel de solicitud individual.
client.tstsximport {trpc } from './utils/trpc';import {useRouter } from 'next/router';functionPostViewPage () {constid =useRouter ().query .id as string;constpostQuery =trpc .post .byId .useQuery ({id }, {trpc : {abortOnUnmount : true } });return null;}
client.tstsximport {trpc } from './utils/trpc';import {useRouter } from 'next/router';functionPostViewPage () {constid =useRouter ().query .id as string;constpostQuery =trpc .post .byId .useQuery ({id }, {trpc : {abortOnUnmount : true } });return null;}