New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-lifecycle-communicator

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-lifecycle-communicator

Helper library that allows communication inside to react lifecycle

latest
Source
npmnpm
Version
0.1.2
Version published
Maintainers
1
Created
Source

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:

// 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
};

Keywords

react

FAQs

Package last updated on 08 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts