#How to handle a form submit result with fetcher?

1 messages · Page 1 of 1 (latest)

rich agate
#

I have a fetcher which I am using to post to a route action from a component in a seperate file. When someone submits the form associated with this fetcher I want to show a Toast that says "success" or "failed" based on the response from the server. Do I do this with a useEffect hook on fetcher.data or is there a better way?

rich agate
#

Bumping this one again, I feel like useEffect is not the right approach for this?

flint lark
#

we are redirecting with searchparams on the same route for example like toast?=success

strange solstice
#

Yes, fetcher.data and fetcher.state together should work well to give you the info you need for showing toast notification.

ashen delta
#

Yeah, I've run into this before as well. I've only managed to get it working via useEffect which feels pretty fragile and wrong. I wish the submit function actually returned a promise that resolved once the action was complete.

low yacht
#
Alem Tuzlak's blog

Optimize server-side toast notifications in Remix apps with Zod-assisted type-safe handling, flash sessions, and seamless client-side display

GitHub

Server side implementation of toast notifications in Remix - Code-Forge-Net/remix-toast