New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@zenstack/react-zen-bus

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zenstack/react-zen-bus

React Zen Bus is a React binding for [Zen Bus](https://github.com/alaboudi/zen-bus).

  • 0.1.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

React Zen Bus ☮️

React Zen Bus is a React binding for Zen Bus.

Installation

yarn add @zenstack/react-zen-bus

or

npm install @zenstack/react-zen-bus

Usage

useSubscribe(:eventBus, :eventToHandlerMap)

The useSubscribe hooks allows your event handlers to subscribe to the event bus when your component mounts. In addition, it will unsubscribe your handlers when the components unmount.

import {createEventBus, EventType, EventHandler} from "@zenstack/zen-bus";
import {useSubscribe} from "@zenstack/react-zen-bus";

const myTodoList = ['Clean Toilet'];
const addToList = (event) => myTodoList.push(event.title);
const logEvent = (event) => console.log(event);

const subscriptions: [EventType<any>, EventHandler<any>][] = [
    ["Todo Added", addToList],
    ["Todo Added", logEvent]
];

/**
 * Once this component mounts, addToLis and logEvent will both 
 * susbcribe to the event bus and execute when an event of type "Todo Added" has been emitted.
 * They both will unsubscribe from the event bus when the component unmounts.
 */
const MyComponent = () => {
    useSubscribe(eventBus, subscriptions);
    
    return (
        <div>
            ...
        </div>
    );
}

Keywords

FAQs

Package last updated on 13 Feb 2021

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc