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}</>;
}
Only reason I can think of is if you already use RxJS and prefer it over Callbags and callbag operators.
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