Skip to content

TrendingTechnology/use-observable

Repository files navigation

use-observable

"Plug and play" for observables in React Apps!

All Contributors Commitizen friendly PRs Welcome coc-badge semantic-release styled with prettier NPM JavaScript Style Guide

Ever had an Observable holding data that you need to maintain in the state of your React App? This method bridges that gap.

It receives an Observable, subscribes to it, and stores the current version in a react state, ensuring that it persists between re-renders.

Note that you can use it multiple times, with various Observables.

Install

npm install @ngneat/use-observable

Usage

import { interval } from "rxjs";
import { useObservable } from "@ngneat/use-observable";

const source = interval(1000);

function App() {
  const [count] = useObservable(source);

  return <h1>{count}</h1>;
}

useObservable can take the initial value as the second parameter - useObservable(source$, initialValue). If the source fires synchronously immediately (like in a BehaviorSubject), the value will be used as the initial value.

Contributors ✨

Thanks goes to these wonderful people (emoji key):

Netanel Basal
Netanel Basal


Inbal Sinai

This project follows the all-contributors specification. Contributions of any kind welcome!

About

"Plug and play" for observables in React Apps!

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors