rxh
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

React Hook for RxJS

React ❤️ RxJS

Install

Using npm

npm install rxh

Using yarn

yarn add rxh

API

type InitialState<State> = State | (() => State);
function useObservable<State>(obs: Observable<State>): State | undefined;
function useObservable<State>(obs: Observable<State>, initialState: InitialState<State>): State;
function useObservable<State>(cb: () => Observable<State>): State | undefined;
function useObservable<State>(cb: () => Observable<State>, initialState: InitialState<State>): State;

Usage

import React from 'react';
import ReactDOM from 'react-dom';
import {timer} from 'rxjs';
import {useObservable} from 'rxh';

const timerObservable = timer(0, 1000)

function CountDown() {
  const countDown = useObservable(timerObservable, 0)
  return (
    <div>{ countDown }</div>
  )
}

function App() {
  return (
    <div className="App">
      <CountDown />
    </div>
  );
}

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

/rxh/

    Package Sidebar

    Install

    npm i rxh

    Weekly Downloads

    1

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    5.61 kB

    Total Files

    8

    Last publish

    Collaborators

    • yuuko