All Projects → ngneat → react-rxjs

ngneat / react-rxjs

Licence: other
🔌 "Plug and play" for Observables in React Apps!

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to react-rxjs

rdeco
响应式对象编程库,从时间和空间上解耦你的代码
Stars: ✭ 54 (+50%)
Mutual labels:  rxjs, reacthooks
angular-model-pattern-example
Model pattern for Angular (2, 4, ...), manage and share your state with simple services using RxJS Subjects and Observables
Stars: ✭ 37 (+2.78%)
Mutual labels:  rxjs
fractal-component
A javascript library that can help you to encapsulate decoupled UI component easily
Stars: ✭ 13 (-63.89%)
Mutual labels:  reacthooks
ng-effects
Reactivity system for Angular. https://ngfx.io
Stars: ✭ 46 (+27.78%)
Mutual labels:  rxjs
thruway.js
RxJS WAMPv2 Client
Stars: ✭ 28 (-22.22%)
Mutual labels:  rxjs
rxhr
Tiny Observable based HTTP client for browsers
Stars: ✭ 15 (-58.33%)
Mutual labels:  rxjs
react-nonav
Experimental React Native declarative navigation
Stars: ✭ 58 (+61.11%)
Mutual labels:  rxjs
angular-ebook
Contains the code for the Step-by-Step Angular Guide Ebook
Stars: ✭ 28 (-22.22%)
Mutual labels:  rxjs
react-rxjs-flux
a small library for creating applications based on unidirectional data flow
Stars: ✭ 22 (-38.89%)
Mutual labels:  rxjs
rxjs-sort-visualization
sorting algorithm visualization build by Rxjs 🐠
Stars: ✭ 16 (-55.56%)
Mutual labels:  rxjs
observer-spy
This library makes RxJS Observables testing easy!
Stars: ✭ 310 (+761.11%)
Mutual labels:  rxjs
ngx-translate-module-loader
Highly configurable and flexible translations loader for @ngx-translate/core
Stars: ✭ 31 (-13.89%)
Mutual labels:  rxjs
ng-observe
Angular reactivity streamlined...
Stars: ✭ 65 (+80.56%)
Mutual labels:  rxjs
observable-profiler
Tracks new & disposed Observable subscriptions
Stars: ✭ 41 (+13.89%)
Mutual labels:  rxjs
redis-patterns-console
An interactive (and reactive) console to try and go into the deep of Redis and its patterns!
Stars: ✭ 22 (-38.89%)
Mutual labels:  rxjs
learnrxjs
Русскоязычная документация RxJS
Stars: ✭ 20 (-44.44%)
Mutual labels:  rxjs
ccex-api
Cryptocurrency exchanges realtime api wrapper
Stars: ✭ 29 (-19.44%)
Mutual labels:  rxjs
fullstack-typescript
A demo project of a full stack typescript application
Stars: ✭ 28 (-22.22%)
Mutual labels:  rxjs
firebase-ignite
Firebase PWA Boilerplate
Stars: ✭ 12 (-66.67%)
Mutual labels:  rxjs
rxrest
Reactive rest library
Stars: ✭ 33 (-8.33%)
Mutual labels:  rxjs

"Plug and play" for RxJS Observables in React Apps!

@ngneat/react-rxjs commitizen PRs coc-badge semantic-release styled with prettier

npm install @ngneat/react-rxjs

useObservable

Ever had an Observable holding data that you need to maintain in the state of your React App? This hook 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.

import { interval } from 'rxjs';
import { take } from 'rxjs/operators';
import { useObservable } from '@ngneat/react-rxjs';

const interval$ = interval(1000);

function CounterComponent() {
  const [counter] = useObservable(interval$);
  const [counter, { error, completed, subscription }] = useObservable(interval$.pipe(take(3)));

  return <h1>{counter}</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.

You can also pass a dependencies:

import { useObservable } from '@ngneat/react-rxjs';

const SomeComponent = ({ id }: { id: string }) => {
  const [state] = useObservable(getStream$(id), { deps: [id] })

  return state;
}

useUntilDestroyed

The useUntilDestroyed hook returns an object with two properties:

  • untilDestroyed: An operator that unsubscribes from the source when the component is destroyed.

  • destroyed - An observable that emits when the component is destroyed.

import { interval } from 'rxjs';
import { useUntilDestroyed } from '@ngneat/react-rxjs';

function CounterComponent() {
  const { untilDestroyed } = useUntilDestroyed();

  useEffect(() => {
    interval(1000).pipe(untilDestroyed()).subscribe(console.log)
  }, [])

  return ...;
}

useEffect$

The useEffect$ hook receives a function that returns an observable, subscribes to it, and unsubscribes when the component destroyed:

import { useEffect$ } from '@ngneat/react-rxjs';

function loadTodos() {
  return fromFetch('todos').pipe(tap({
    next(todos) {
      updateStore(todos);
    }
  }));
}

function TodosComponent() {
  const [todos] = useObservable(todos$);

  useEffect$(() => loadTodos());
  useEffect$(() => loadTodos(), deps);

  return <>{todos}</>;
}

useFromEvent

It's the fromEvent observable, but with hooks:

export function App() {
  const [text, setText] = useState('');

  const { ref } = useFromEvent<ChangeEvent<HTMLInputElement>>('keyup', (event$) =>
    event$.pipe(
      debounceTime(400),
      distinctUntilChanged(),
      tap((event) => setText(event.target.value))
    )
  );

  return (
    <>
     <input ref={ref}>
     { text }
    </>
  )
Icons made by Freepik from www.flaticon.com
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].