How do I run a function inside the browser after the call to action()
returns?
#8129
-
For example, let's say I have a sign-in form, when user submits this form, it will call the But what if I want to show a toast popup instead of rendering an error message above the form? This sounds super simple or pretty straightforward but I don't know how to do it. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
hi @off99555 to display the same error message multiple times from the useEffect, you have only to update the array of dependencies this way 👇🏻 const actionData = useActionData<typeof action>()
useEffect(()=>{
if(actionData){
if("errorMessage" in actionData){
displayErrorToast(actionData.errorMessage) // call your toast function here
}
}
},[actionData]) or you can this library to handle your toasts 👇🏻 |
Beta Was this translation helpful? Give feedback.
-
I used this mechanism to trigger toast messages on the Remix site I built about six months ago, but it silently stopped working at some point. I eventually got around it by making use of the |
Beta Was this translation helpful? Give feedback.
-
If you are using useFetcher you won't receive anything in useActionData |
Beta Was this translation helpful? Give feedback.
hi @off99555 to display the same error message multiple times from the useEffect, you have only to update the array of dependencies this way 👇🏻
or you can this library to handle your toasts 👇🏻
https://github.com/Code-Forge-Net/remix-toast