npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@alcadur/react-events-hook

v1.1.0

Published

Helps in easy communication between React components as also with external sources

Downloads

352

Readme

react-events-hook

Simple Observer pattern for React.

Live Demo

npm package

Installation

npm i @alcadur/react-events-hook

What for?

Useful for communication between components in different parts of the view.

Using standard React mechanisms, it's also possible to synchronize with external events.

Lets look at an example:

image

If we want to change background colors for C1, C2 and C3 from C6 we have few options:

  1. use context

  2. use global state

  3. props drilling

    chrome-ZO2l-FT6NWj.png

With events, we can avoid unnecessary boilerplate.

chrome-69c-Hd-SCHv-C.png chrome-M22485Lpnz.gif

Docs

onEvent

onEvent is a function that subscribes to event outsite of React context.

:warning: If you want to use onEvent in react component without useEvents hook, make sure to not add a new listiner on each render.

onEvent('eventName', (...args) => console.log('event fired with: ', args));

useEvents

Use to subscribe to events in React components.

    const { onEvent, emitEvent, removeEvent } = useEvents({ eventName: (...args) => console.log('event fired with: ', args) })

Event name can be: string, number or symbol

export const Events = {
  C4_TITLE_CHANGE: Symbol(),
  REMOVE_LEFT_CHILD: "remove-element",
  CHANGE_COLOR: 3
} as const;

You don't need to use useEvents hook to emit or remove events.

emitEvent

emitEvent is a function that emits single event.

emitEvent('eventName', 'some data');
emitEvent('eventWithParams', 1, 2, 3);

emitEvent.memo

emitEvent.memo remembers the last emitted value and triggers a new callback immediately with that value. To clear memorized value, call emitEvent.memo(undefined) or to avoid extra emission, use clearMemo (described below)

onEvent('eventName', (data) => console.log(data)) 
emitEvent('eventName', 'some data');
// expected log: some data

emitEvent('eventName', 'some data');
onEvent('eventName', (data) => console.log(data))
// no logs expected, event was emited before subscription

emitEvent.memo('eventName', 'some data');
onEvent('eventName', (data) => console.log(data))
// expected log: some data

emitEvent.memo('eventName', 'some data');
emitEvent('eventName', 123); // value emited without memo
onEvent('eventName', (data) => console.log(data))
// expected log: some data

There no difference between directly usage of emitEvent and emitEvent returned from useEvents hook.

removeEvent

removeEvent is a function that removes event listener.

const eventHandler = () => console.log('event fired');
onEvent('eventName', eventHandler);
removeEvent('eventName', eventHandler);

There no difference between directly usage of removeEvent and removeEvent returned from useEvents hook.

clearMemo

clearMemo removes the last memorized event emitted value

clearMemo('eventName');

There no difference between directly usage of clearMemo and clearMemo returned from useEvents hook.