ReactJS event bus using hooks

in reactjs •  2 years ago 

React hook to subscribe and dispatch events across React components.

Github: https://github.com/fabienjuif/use-bus

Register to an event (and react to it)

image.png

  1. Import the hook useBus.
  2. Register to an event name, here @@ui/ADD_ITERATION.
  3. React to this, here an anonymous function that increment a number.

Dispatch an event

image.png

  1. Import dispatch and call it with the event you want to send.
Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!