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.tsts// @filename: utils.tsimport {createTRPCNext } from '@trpc/next';export consttrpc =createTRPCNext <AppRouter >({config () {return {// ...abortOnUnmount : true,};},});
client.tsts// @filename: utils.tsimport {createTRPCNext } from '@trpc/next';export consttrpc =createTRPCNext <AppRouter >({config () {return {// ...abortOnUnmount : true,};},});
Por solicitud
También puedes sobrescribir este comportamiento a nivel de solicitud individual.
client.tsts// @filename: pages/posts/[id].tsximport {trpc } from '~/utils/trpc';constPostViewPage :NextPageWithLayout = () => {constid =useRouter ().query .id as string;constpostQuery =trpc .post .byId .useQuery ({id }, {trpc : {abortOnUnmount : true } });return (...)}
client.tsts// @filename: pages/posts/[id].tsximport {trpc } from '~/utils/trpc';constPostViewPage :NextPageWithLayout = () => {constid =useRouter ().query .id as string;constpostQuery =trpc .post .byId .useQuery ({id }, {trpc : {abortOnUnmount : true } });return (...)}