Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pascalallen/react-event-dispatcher
Repository for the @pascalallen/react-event-dispatcher NPM package. A lightweight event dispatcher for React.
https://github.com/pascalallen/react-event-dispatcher
dispatcher events react typescript
Last synced: 8 days ago
JSON representation
Repository for the @pascalallen/react-event-dispatcher NPM package. A lightweight event dispatcher for React.
- Host: GitHub
- URL: https://github.com/pascalallen/react-event-dispatcher
- Owner: pascalallen
- License: other
- Created: 2023-01-20T00:17:39.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-03-20T23:03:40.000Z (over 1 year ago)
- Last Synced: 2024-09-05T10:49:07.425Z (2 months ago)
- Topics: dispatcher, events, react, typescript
- Language: TypeScript
- Homepage:
- Size: 192 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# React Event Dispatcher
A lightweight event dispatcher for React.
## Installation
Use the package manager [yarn](https://classic.yarnpkg.com/lang/en/docs/install) to install @pascalallen/react-event-dispatcher.
```bash
yarn add @pascalallen/react-event-dispatcher
```## Usage
### Dispatch
```typescript
import { DomainEvent, eventDispatcher } from '@pascalallen/react-event-dispatcher';const event: DomainEvent = {
name: 'USER_ADDED',
data: {
id: '01GQ7S8624BN2Q2S3HNZH5SGDJ'
}
};eventDispatcher.dispatch(event);
```### Subscribe
```typescript
import { useEffect } from "react";
import { DomainEvent, useEvent } from '@pascalallen/react-event-dispatcher';const userAddedEvent: DomainEvent | undefined = useEvent('USER_ADDED');
useEffect(() => {
userAddedEvent?.id && console.log('User added');
}, [userAddedEvent]);
```