seb1S
tRPC7mo ago
9 replies
seb1

How to abort a streaming mutation

I have a streaming mutation working, but I need to be able to abort it. I've seen this thread but that syntax doesn't appear to be valid for the React version.

If I do this:
foo.mutate(
  { exampleInputData: 'hello world' },
  { signal: abortController.signal },
)


then I get the type error that 'signal' does not exist on mutation options.

If I try the new tanstack-query client syntax (from this migration guide), well that also doesn't work because the property mutationOptions doesn't exist in this call:

const mutation = useMutation(trpc.threads.example.mutationOptions());


That migration guide doesn't specify how the useTRPC custom hook is meant to be implemented, so I suspect there's something I'm missing there?

So my main questions are:
1. Is it possible to abort a streaming mutation client-side with a react trpc client?
2. if yes, can this be done using the old syntax? or if we need to use the new syntax, what code for the useTRPC hook makes the types check out?

Thanks in advance!
Was this page helpful?