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: 3 months ago
JSON representation
Use global events in your React app with hooks
- Host: GitHub
- URL: https://github.com/nicolaslopezj/react-app-events
- Owner: nicolaslopezj
- Created: 2020-01-20T13:14:09.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-04-02T06:58:38.000Z (over 2 years ago)
- Last Synced: 2025-03-13T23:03:33.315Z (4 months ago)
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/react-app-events
- Size: 227 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
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)
})
returnHello 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
)
}
```