react-hooks-event-listener
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Hooks provides easy way to connect to event-listener within react component

npm

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')
  })
}

Package Sidebar

Install

npm i react-hooks-event-listener

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

9.32 kB

Total Files

15

Last publish

Collaborators

  • zvs001