ayemitter-hook
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

ayemitter-hook

React hook component for ayemitter.

Usage

yarn add ayemitter ayemitter-hook
import { EventEmitter } from 'ayemitter';
import { useEventChangeHandler } from 'ayemitter-hook';

const emitter = new EventEmitter<string>();
const Component = () => {
  const [state, setState] = useState('state1');
  useEventChangeHandler(
    emitter,
    () => {
      console.log('Hello!');
    },
    [state]
  ); // state is a dependency

  // The handler is rebinded to the emitter everytime the
  // handler or a dependency changes.

  return; // ...
};

API

const useEventChangeHandler: <T>(
  eventEmitter: EventEmitter<T>,
  handler: (payload: T) => void | Promise<void>,
  dependencies?: any[]
) => void;

Package Sidebar

Install

npm i ayemitter-hook

Weekly Downloads

0

Version

1.0.2

License

MIT

Unpacked Size

5.22 kB

Total Files

8

Last publish

Collaborators

  • lukasbach