TanStackT
TanStack7mo ago
1 reply
specific-silver

Customizing error messages in global onError callback.

Very often I would like to curate the messages shown in a globally configured toast message that is dispatched by a global onError or onSuccess callback on a per mutation basis. For example, a confirmation message could say Successfully created [name_of_thing] where [name_of_thing] comes from the mutation response. In the case of an error, [name_of_thing] may need to come from local state if the network request fails. I can't use the
meta
option because the data isn't static. I thought about formatting and returning a custom message in the local onSuccess and onError definition but I don't know if the global handler is able to grab this information. I may be overthinking this but I'm not sure how to approach this cleanly. Thanks.
Was this page helpful?