0.1.2 • Published 4 years ago

react-datastream v0.1.2

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

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!