vendredi 8 avril 2016

When using React, how can I make a general JavaScript event listener?

I'm, using React and I'm becoming confused as to how I can implement a general Javascript event emitter. I would like to attach React to an event emitter which updates the UI when a particular event occurs.

For example, a user can become logged out in a number of different ways, all of which have a shared UI change: The user explicitly presses "Log Out", the server logs the user out and sends a message, the connection was dropped and the app knows to treat this as a log out, etc...

I would like to send each of these "LoggedOut" events, which have a shared UI change, to a single event listener which then calls the correct React callback function.

Is this something which should be done, and if so, how do I do this properly?




Aucun commentaire:

Enregistrer un commentaire