Files
trpc-nuxt/docs/content/1.get-started/5.tips/5.aborting-procedures.md
2022-12-18 23:31:55 -08:00

580 B

title
title
Aborting Procedures

Aborting Procedures

tRPC adheres to the industry standard when it comes to aborting procedures. All you have to do is pass an AbortSignal to the query-options and then call its parent AbortController's abort method.

export default function useGetTodo(id: number) {
  const { $client } = useNuxtApp()
  const ac = new AbortController()

  onScopeDispose(() => {
    ac.abort()
  })
  
  return useAsyncData(() => {
    return $client.todo.getTodo.query(id, {
      signal: ac.signal
    })
  })
}