Next.js Discord

Discord Forum

How to use toasts with useActionState?

Answered
Southern rough shrimp posted this in #help-forum
Open in Discord
Southern rough shrimpOP
I'd like to create a toast whenever the action has finished, either successfully or not. The action already returns if it was successful or not, but not sure how you're meant to handle it now you just plug the action into the React hook
Answered by B33fb0n3
you can check the formState inside a useEffect like this:
useEffect(() => {
  // work with your formstate
  toast("something happend to formState")
}, [formState])
View full answer

1 Reply

@Southern rough shrimp I'd like to create a toast whenever the action has finished, either successfully or not. The action already returns if it was successful or not, but not sure how you're meant to handle it now you just plug the action into the React hook
you can check the formState inside a useEffect like this:
useEffect(() => {
  // work with your formstate
  toast("something happend to formState")
}, [formState])
Answer