Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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)
- Host: GitHub
- URL: https://github.com/hc-oss/react-gbus
- Owner: hc-oss
- License: mit
- Created: 2019-12-05T09:13:25.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-07-11T01:57:01.000Z (over 1 year ago)
- Last Synced: 2024-11-29T08:17:39.195Z (about 2 months ago)
- Topics: broadcast, emit, eventemitter, events, pubsub, react, subscribe
- Language: JavaScript
- Size: 295 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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)