How to create a global toast component?

UI Components for React
Post Reply
Dekso
Posts: 2
Joined: 05 Jun 2018, 07:10

20 Mar 2022, 07:52

I wonder how I can use the toast component globally? Like react-toastify for example. I wish to add it on my axios interceptor for error messages.

Melloware
Posts: 3716
Joined: 22 Apr 2013, 15:48

21 Mar 2022, 14:23

Just create a Toast that is in your main Application and get a "ref" to it and use that Ref to call the Toast.

I do something similar in my app. I use library called use-between so I can store that ref in a shared hook that I can use anywhere in my app. Check out use-between its simple and slick.
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

Post Reply

Return to “PrimeReact”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 3 guests