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

0.0.3 • Public • Published

React Events

Emit and listen to events in a React application.

Install

npm i react-events-hook

Usage

Configuration

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

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

Emitting

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

Listening

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

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

useEvent()

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>
  )
}

Readme

Keywords

Package Sidebar

Install

npm i react-events-hook

Weekly Downloads

0

Version

0.0.3

License

ISC

Unpacked Size

5.18 kB

Total Files

9

Last publish

Collaborators

  • larrrssss