Skip to content

must/use-rxjs-observable

Repository files navigation


React Callbag Streams

tests coverage version


Use RxJS observables as a react hook. This work is based on / is an adaptation of react-callbag-streams and use-callbag

npm i use-rxjs-observable
import useRxJSObservable from 'use-rxjs-observable';

import { interval } from 'rxjs';
import { map } from 'rxjs/operators';

function App() {
  const initial = 5;
  const count = useRxJSObservable(initial, () => (
    interval(1000).pipe(
      map((i: number) => initial + i + 1)
    )
  ));

  return <>{count}</>;
}

► Playground


Why not Callbags

Only reason I can think of is if you already use RxJS and prefer it over Callbags and callbag operators.



Contribution

Be nice and respectful, more importantly super open and welcoming to all.

👉 Useful commands for working on this repo:

git clone https://github.com/must/use-rxjs-observable.git
npm i              # --> install dependencies
npm start          # --> serves `samples/index.tsx` on localhost:3000
npm test           # --> run all tests
npm run cov:view   # --> view code coverage

About

Use RxJS Observables as a React hook

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published