react-use-events

0.0.1 • Public • Published

react-use-events

Simple react hooks for event handling.

🚀 Getting Started

Using npm:

npm install --save react-use-events

Using yarn:

yarn add react-use-events

✍️ Usage

import React, { useEffect } from 'react';
import { useEvent, emitEvent } from 'react-use-events';

const eventName = 'SOME_EVENT_NAME';

export default () => {
  // When your component is unmounted, the listener will be cleared.
  const [ data ] = useEvent(
    eventName,
    // Define some initial data.
    'No data received.',
  );
  useEffect(
    () => {
      // You can call this anywhere in your app; all registered
      // components will be updated.
      emitEvent(
        eventName,
        'Received some data.',
      );
    },
    [],
  );
  return (
    <div>
      {data}
    </div>
  );
};

✌️ License

MIT

Package Sidebar

Install

npm i react-use-events

Weekly Downloads

2

Version

0.0.1

License

MIT

Unpacked Size

3.46 kB

Total Files

5

Last publish

Collaborators

  • cawfree