react-datastream
TypeScript icon, indicating that this package has built-in type declarations

0.1.2 • Public • Published

React-DataStream

react-datastream is an easy way for your components to talk to each other. It will make your "Prop Drilling" a thing of the past.

  • Easy to use and integrate
  • No boilerplate
  • Minimal react code changes
  • Magic

How it works!

react-datastream uses streams with a pub/sub model, any component can publish to the stream and any component can subscribe to a stream. any to any relationship.

Installation

$ npm install react-datastream

Usage

Import it in your code

import datastream from "react-datastream";

declare a shared stream name

const STREAM_NAME = "DATA_STREAM"

publish changes

datastream.publish(STREAM_NAME, value);

listen for changes

datastream.subscribe(STREAM_NAME, (value) => {console.log(value)});

Dont forget to unsubscribe to prevent orphaned callbacks

stream: Stream;

componentDidMount() {
  this.stream = datastream.subscribe(STREAM_NAME, value => console.log(value));
}

componentWillUnmount() {
  this.stream.unsubscribe()
}

Cheers!

Package Sidebar

Install

npm i react-datastream

Weekly Downloads

2

Version

0.1.2

License

MIT

Unpacked Size

6.93 kB

Total Files

5

Last publish

Collaborators

  • zdeveloper