1.0.7 • Published 2 years ago

@naporin0624/react-flow v1.0.7

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

react-flow

A library that connects rxjs to React.

Observables registered with the same key are subscribed only once in total.

Image from Gyazo

Usage

import ReactDOM from "react-dom";
import { Subject, scan } from "rxjs";
import { Provider, useFlow } from "@naporin0624/react-flow";

const root = new Subject<number>();
const counter$ = root.pipe(
  scan<number, number>((acc, value) => acc + value, 0)
);
const increment = () => root.next(1);
const decrement = () => root.next(-1);

const Counter = () => {
  const counter = useFlow("counter", counter$) ?? 0;

  return (
    <div>
      <p>counter: {counter}</p>
      <div>
        <button onClick={increment}>+</button>
        <button onClick={decrement}>-</button>
      </div>
    </div>
  );
};

// The counter subscribe is called only once.
const App = () => {
  return (
    <Provider>
      <div>
        <p>counter1</p>
        <Counter />
      </div>
      <div>
        <p>counter2</p>
        <Counter />
      </div>
    </Provider>
  );
};

ReactDOM.render(<App />, document.getElementById("root"));

LICENSE

MIT

1.0.7

2 years ago

1.0.6

2 years ago

1.0.2

2 years ago

1.0.4-alpha.0

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

1.0.5-alpha.0

2 years ago

1.0.5

2 years ago

1.0.3

2 years ago

1.0.0-alpha.0

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.2

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago

0.0.1-alpha.0

2 years ago