react-hooks-event-listener
v1.0.0
Published
Hooks provides easy way to connect to event-listener within react component
Downloads
57
Maintainers
Readme
Hooks provides easy way to connect to event-listener within react component
Install
yarn add react-hooks-event-listener
or
npm i -S react-hooks-event-listener
Usage
import useEventListener from 'react-hooks-event-listener'
import { EventEmitter } from 'events'
const eventEmitter = new EventEmitter()
setInterval(() => {
eventEmitter.emit('change')
}, 1000)
function App() {
useEventListener(eventEmitter, 'change', () => {
console.log('Received change event')
})
}