Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/hc-oss/react-gbus

global event bus hook for react (pub/sub)
https://github.com/hc-oss/react-gbus

broadcast emit eventemitter events pubsub react subscribe

Last synced: about 2 months ago
JSON representation

global event bus hook for react (pub/sub)

Awesome Lists containing this project

README

        

# react global event bus

Global event bus hook for react

![GitHub Actions Status](https://github.com/harshzalavadiya/react-gbus/workflows/NodeJS/badge.svg)
![NPM](https://img.shields.io/npm/v/react-gbus.svg)
![gzip](https://badgen.net/bundlephobia/minzip/react-gbus)

## 🔧 Installation

```bash
npm install --save react-gbus
```

## ✨ Features

- 📢 Broadcast(emit) from anywhere (not limited to react components)
- 🍃 Ultra lightweight less then 1KB
- ✌ Written w/ TypeScript

## 📦 Usage

```tsx
import React, { useState } from "react";

import BusProvider, { useListener, emit } from "react-gbus";

const FRUIT_CHANGE = "fch";

function FruitViewer() {
const [Fruit, setFruit] = useState("Choose your Fruit");

useListener(setFruit, [FRUIT_CHANGE]);

return

{Fruit}

;
}

const FruitChooser = () => (


emit(FRUIT_CHANGE, "🍎")}>Apple
emit(FRUIT_CHANGE, "🥭")}>Mango
emit(FRUIT_CHANGE, "🍍")}>Pineapple

);

const App = () => (




);
```

## License

MIT © [harshzalavadiya](https://github.com/harshzalavadiya)