React-toastify: Toast not showing

Created on 1 Aug 2018  路  10Comments  路  Source: fkhadra/react-toastify

Hello,

I'm facing a problem displaying my toast.
I have a main project wich as another project as a dependency. This project is a minified library that i referenced with npm.
In the main project I set the somewhere.
If I call the method toast() from the library the toast is not display. It is display if I call toast from the main project.
I tried to things :

  • If I add a in the library the toast from the library are displayed. But I have then 2 toastcontainer...
  • Other solution I found is passing the toast object imported in the main project as a reference to the library then the toast are displayed (without adding the toastcontainer in the library).

I think the Toaster doesn't find the ToastContainer in the main project when the toast() is imported in the
library.

Do you have any clue?
For the moment I'm passing the toast() as a props to my library but I don't like it...

inactive question

Most helpful comment

Before declaring your class, add the following line:

toast.configure();

All 10 comments

Hello @alb3ric ,

Is it possible to reproduce your setup?

The lib doesn't work with 2 ToastContainer for the moment .

Hello @fkhadra,

I'm going to try to make a small project reproducing the problem. I keep you in touch when it s done.

Hello @fkhadra

I did 2 test repository.
You can find the repository for the library here : https://github.com/alb3ric/ToastLib.git
And a repository with a project consuming the library : https://github.com/alb3ric/ToastTest.git

The ToastTest project reference the ToastLib library using : yarn add https://github.com/alb3ric/ToastLib.git

Launching TestToast :

  • Use >yarn to get the dependencies
  • Start debug : npm start

If you execute the ToastTest you can see that the toast is not showing when clicking the test button but showing is clicking the button "test ref".

Hope it helps :)

Thanks @alb3ric, I'll try to have a look at this ASAP.

Hello @alb3ric,

The ToastTest project is not working as expected because it seems that 2 instances of react-toastify are running. You can see that after having a look at the webpack bundle generated by the ToastTest project:

screen shot 2018-08-06 at 16 46 10
screen shot 2018-08-06 at 16 46 35

The library uses an event manager(just a pubsub in fact) to dispatch the notifications. The so-called event manager is bound to the toast object. With the current setup 2 toast object are created.

Maybe you need to adapt the webpack config of ToastLib. I found an interesting issue here.

I'll try to dig more.

Hello @fkhadra

Thx for the input. I'm currently on holidays, I ll try that as soon as I come back! I keep you in touch!

Best regards and thanks for your great work!

You're welcome @alb3ric bonne vacances!

@fkhadra is this issue solved ?

I have the same problem

Before declaring your class, add the following line:

toast.configure();

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AllyssonAlas picture AllyssonAlas  路  4Comments

albert-olive picture albert-olive  路  5Comments

SmileSydney picture SmileSydney  路  4Comments

jorgecuesta picture jorgecuesta  路  5Comments

nirsky picture nirsky  路  3Comments