T
TanStack9mo ago
sunny-green

Mutations throwing errors always

I was heavily under the impression, that errors thrown from query/mutation functions are handled by the hook (hence the properties isError and error and the onError callback). Therefore I was under the impression I could use mutateAsync, for instance, without any try/catch or .catch() but this doesn't seem to be the case. If mutationFn throws an error, it is thrown all the way up. What, then, is the point of the error return value of the hook? Is there some definition I can make to prevent mutations of ever throwing errors like this, so that I can rely of the hook value?
1 Reply
stormy-gold
stormy-gold9mo ago
That is only true for mutate. With mutateAsync you have to handle errors/rejections yourself.

Did you find this page helpful?