Skip to content
On this page

rxjs-use-hooks

This is a port of VueUse's RxJS add-on, enabling a natural way of using RxJS in React.

Install

bash
npm i rxjs-use-hooks rxjs

Example

tsx
import { useObservable } from "rxjs-use-hooks";
import { Observable } from "rxjs";

const obs = new Observable((subscriber) => {
  let count = 0;

  subscriber.next(count++);

  setInterval(() => {
    subscriber.next(count++);
  }, 1000);
});

export default function App() {
  const count = useObservable(obs);
  return <p>{count}</p>;
}