Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/nicolaslopezj/react-app-events
- Owner: nicolaslopezj
- Created: 2020-01-20T13:14:09.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-04-02T06:58:38.000Z (over 1 year ago)
- Last Synced: 2024-10-03T08:54:53.522Z (about 1 month ago)
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/react-app-events
- Size: 227 KB
- Stars: 2
- Watchers: 2
- 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
)
}
```