timolins / react-hot-toast

Smoking Hot React Notifications 🔥
https://react-hot-toast.com
MIT License
9.79k stars 331 forks source link

How display Toaster from external library ? #108

Closed Vincent-Alibert closed 1 year ago

Vincent-Alibert commented 3 years ago

Hello, I use a personal library which exposes components. Within its components I use toast.success("test message");. However, I cannot make the toasts appear in the main application since with the actions of the library components. I have to add the <Toaster/> in my components for the toasts to appear.

What 's the solution to add only <Toaster/> on the main application ?

exemple :

import { Toaster } from 'react-hot-toast';
import ButtonCustom from 'customLib';

const App = () => {
  return (
    <div>
      <ButtonCustom />
      <Toaster />
    </div>
  );
};

since customLib

import toast from 'react-hot-toast';

const notify = () => toast.success('Here is your toast.');

const ButtonCustom = () => {
  return (
    <div>
      <button onClick={notify}>Make me a toast</button>

    </div>
  );
};
export default ButtonCustom

Thanks for the help

Joshuapwilley commented 1 year ago

I've documented a solution for this issue here: https://github.com/timolins/react-hot-toast/issues/223#issuecomment-1353375964

timolins commented 1 year ago

I'll close this in favour of @Joshuapwilley solution