react-app-events
TypeScript icon, indicating that this package has built-in type declarations

2.0.2 • Public • Published

React App Events

Use global events in your React app with hooks

Install the package

yarn add react-app-events

No extra setup is needed

Listen for events

We use a hook for event listener.

import React from 'react'
import useOnEvent from 'react-app-events/lib/useOnEvent'

export default function ComponentA(props) {
  useOnEvent('buttonClicked', data => {
    console.log(data)
  })
  return <div>Hello world</div>
}

Fire events

import React from 'react'
import fireEvent from 'react-app-events/lib/fireEvent'

export default function ComponentB(props) {
  return (
    <div>
      <button
        onClick={event => {
          fireEvent('buttonClicked', event)
        }}>
        Click me
      </button>
    </div>
  )
}

Readme

Keywords

none

Package Sidebar

Install

npm i react-app-events

Weekly Downloads

161

Version

2.0.2

License

MIT

Unpacked Size

10.4 kB

Total Files

31

Last publish

Collaborators

  • nicolaslopezj