https://github.com/iamcco/rxh
RxJS hook for React with no magic
https://github.com/iamcco/rxh
hook hooks react react-hook react-hooks rxjs
Last synced: 11 months ago
JSON representation
RxJS hook for React with no magic
- Host: GitHub
- URL: https://github.com/iamcco/rxh
- Owner: iamcco
- Created: 2020-03-08T12:00:44.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-07-18T21:12:31.000Z (over 2 years ago)
- Last Synced: 2025-02-14T17:05:11.666Z (11 months ago)
- Topics: hook, hooks, react, react-hook, react-hooks, rxjs
- Language: JavaScript
- Homepage:
- Size: 271 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# React Hook for RxJS
React ❤️ RxJS
## Install
Using npm
``` sh
npm install rxh
```
Using yarn
``` sh
yarn add rxh
```
## API
``` typescript
type InitialState = State | (() => State);
function useObservable(obs: Observable): State | undefined;
function useObservable(obs: Observable, initialState: InitialState): State;
function useObservable(cb: () => Observable): State | undefined;
function useObservable(cb: () => Observable, initialState: InitialState): State;
```
## Usage
``` typescript
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 (
{ countDown }
)
}
function App() {
return (
);
}
ReactDOM.render(, document.getElementById('root'));
```