# react-lifecycle-communicator

> Helper library that allows communication inside to react lifecycle

Latest version **0.1.2** (published 2023-07-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-lifecycle-communicator
pnpm add react-lifecycle-communicator
yarn add react-lifecycle-communicator
bun add react-lifecycle-communicator
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2023-07-08 |
| First published | 2023-07-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Yigit Sozer |
| Maintainers | yittoo |
| Keywords | react, communicator, hooks, lifecycle, EventEmitter |

## Links

- npm: https://www.npmjs.com/package/react-lifecycle-communicator
- Repository: https://github.com/yittoo/react-lifecycle-communicator
- Homepage: https://github.com/yittoo/react-lifecycle-communicator#readme
- Issues: https://github.com/yittoo/react-lifecycle-communicator/issues
- npm.io page: https://npm.io/package/react-lifecycle-communicator

## Dependencies (1)

- [eventemitter3](https://npm.io/package/eventemitter3.md) ^5.0.1

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 0.1.2 (latest) — 2023-07-08
- 0.1.1 — 2023-07-08
- 0.1.0 — 2023-07-07
- 0.0.5 — 2023-07-07
- 0.0.4 — 2023-07-07
- 0.0.3 — 2023-07-07
- 0.0.2 — 2023-07-06
- 0.0.1 — 2023-07-06

## README

### React Lifecycle Communicator

A way to connect functionality into react lifecycle with hooks and `eventemitter3` npm package.

#### Installation:
`npm i react-lifecycle-communicator`

or

`yarn add react-lifecycle-communicator`

#### Usage:
```javascript
// myCommunicator.js
import { createCommunicator } from 'react-lifecycle-communicator';

const { dispatch, useCommunicator } =  createCommunicator(defaultEventName);

export { dispatch, useCommunicator };

// dispatch.js
import { dispatch } from  'path-to/myCommunicator';

/**
* Function that allows firing event from outside the React lifecycle
* @param  eventName name to dispatch event on, it has to match the listening `useCommunicator`,
defaults to event name passed to `createCommunicator`
* @param  params passed into Listener function callback of `useCommunicator`
*/
dispatch(eventName, myParams);

// MyComponent.js
import { useCommunicator } from  'path-to/myCommunicator';

const MyComponent = () => {
  /**
  * Function that accepts a callback to fire once an event is emitted from outside lifecycle
  * @param  listener function to fire once an event is emitted from outside lifecycle with dispatch,
  gets params from dispatch into callback
  * @param  eventName name to listen event on, it has to match the firing `dispatch`,
  defaults to event name passed to `createCommunicator`
  */
  useCommunicator(listener, eventName);

  // ... my component logic
};
```

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