https://github.com/utsuboco/events
https://github.com/utsuboco/events
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/utsuboco/events
- Owner: utsuboco
- Created: 2021-09-16T08:17:08.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-02-24T02:59:42.000Z (about 3 years ago)
- Last Synced: 2025-04-05T21:34:33.255Z (about 1 year ago)
- Language: TypeScript
- Homepage: https://codesandbox.io/s/utsubo-events-4q3mi
- Size: 84 KB
- Stars: 14
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# @utsubo/events
Minimalist library to emit and receive custom events.
```bash
yarn add @utsubo/events
```
## Example
```ts
import { onEvent, offEvent, emitEvent, useEvent } from '@utsubo/events'
// Create an event listener
const handler = (e) => console.log('event', e)
onEvent('event', handler, { once: false })
// Dispatch a payload to event listeners
emitEvent('event', 'event data')
// Remove the event listener
offEvent('event', handler, { once: false })
// React hook bindings to create reactive handlers.
function Component() {
useEvent('event', (e) => console.log('event', e), [key], { once: false })
}
```