# react-events-hook

> Emit and listen to events in a React application

Latest version **0.0.3** (published 2022-09-24) · ISC license · 0 weekly downloads

## Install

```sh
npm install react-events-hook
pnpm add react-events-hook
yarn add react-events-hook
bun add react-events-hook
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2022-09-24 |
| First published | 2022-09-24 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 5.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | larrrssss |
| Keywords | react, events, hook, global |

## Links

- npm: https://www.npmjs.com/package/react-events-hook
- Repository: https://github.com/larrrssss/react-events-hook
- Homepage: https://github.com/larrrssss/react-events-hook#readme
- Issues: https://github.com/larrrssss/react-events-hook/issues
- npm.io page: https://npm.io/package/react-events-hook

## Dependencies (1)

- [react](https://npm.io/package/react.md) ^18.2.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.0.3 (latest) — 2022-09-24
- 0.0.1 — 2022-09-24

## README

# React Events

Emit and listen to events in a React application.

## Install

```sh
npm i react-events-hook
```

## Usage

### Configuration

```ts
import { Event } from 'react-events-hook';

const ALERT = new Event<{ message: string }>();
```

### Emitting

```ts
ALERT.emit({ message: 'Big uff' });
```

### Listening

```ts
const cleanup = ALERT.on((data) => {
  // ...
});

// Use cleanup function on component unmount
cleanup();
```

### useEvent()

```tsx
import React from 'react';

import { useEvent } from 'react-events-hook';

export const App: React.FC = (props) => {

  useEvent(ALERT, (data) => {
    // ...
  });

  return (
    <div>
      <h1>Hello World</h1>
    </div>
  )
}
```

---
_Source: https://npm.io/package/react-events-hook · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
