Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/nicolaslopezj/react-app-events

Use global events in your React app with hooks
https://github.com/nicolaslopezj/react-app-events

Last synced: 25 days ago
JSON representation

Use global events in your React app with hooks

Awesome Lists containing this project

README

        

# 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.

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

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

Hello world

}
```

## Fire events

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

export default function ComponentB(props) {
return (


{
fireEvent('buttonClicked', event)
}}>
Click me


)
}
```