DEV Community

Discussion on: Using a Promise in a click eventListener - more than once.

Collapse
 
fearless23 profile image
Jaspreet Singh

You can use Rxjs Subject and subscribe to it.

const sub = new Subject()

// Inside Event Listener Callback
sub.next(e.target.id)

// Outside or wherever you want
sub.subscribe( id => {
// add your stuff here
})

.subscribe will fire everytime button is clicked or event is fired.