DEV Community

Cover image for 🍞Building Toast with React-Toastify and Troubleshooting
Chan
Chan

Posted on

🍞Building Toast with React-Toastify and Troubleshooting

Requirements

Here are the requirements of the <Toast/> UI that I defined

  • It should render regardless of routing. Some of them should render on button clicks while the others should render right after fetching.
  • It should pop up for 3 seconds and disappear.
  • It should be placed on top of everything. Nothing should override it.
  • It should be placed inside the Box on the desktop devices.
  • There should be different texts based on contexts, such as:
    • The upload has been canceled.
    • Contact has been saved successfully.
    • Your account has been deleted successfully.
    • You've signed out of Majorfolio successfully.
    • We'll send you a verification email.

Image description

Restrictions

  • It should be in the top-level component since it should render regardless of routing.
  • It seems hard to place Toast in the right position. It gets worse since there can be multiple Toast Messages.

Therefore, I decided to look into some libraries, and React-Toastify caught my attention.

What React-Toastify offers

React-Toasitify

  • stacks notifications
  • supports swipe to close
  • pause toast when the window loses focus
  • support nice and tidy default animations
  • can display a react component inside the toast
  • sets Toast with role="alert" for accessibility

Positioning Problem

<ToastContainer/> was set with position="bottom-center" prop and it was positioned in the wrong position.

  • to be continued

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More