rx-effects-react
TypeScript icon, indicating that this package has built-in type declarations

1.1.2 • Public • Published

RxEffects: rx-effects-react

rocket

Reactive state and effect management with RxJS. Tooling for React.js.

npm downloads types licence Coverage Status

Documentation

Installation

npm install rx-effects rx-effects-react --save

Usage

The package provides utility hooks to bind the core RxEffects to React components and hooks:

  • useConst – keeps the value as a constant between renders.
  • useController – creates an ad-hoc controller by the factory and destroys it on unmounting.
  • useObservable – returns a value provided by source$ observable.
  • useObserver – subscribes the provided observer or next handler on source$ observable.
  • useSelector – returns a value provided by source$ observable.
  • useQuery – returns a value which is provided by the query.

Example:

// pizzaShopComponent.tsx

import React, { FC, useEffect } from 'react';
import { useConst, useObservable, useQuery } from 'rx-effects-react';
import { createPizzaShopController } from './pizzaShop';

export const PizzaShopComponent: FC = () => {
  // Creates the controller and destroy it on unmounting the component
  const controller = useConst(() => createPizzaShopController());
  useEffect(() => controller.destroy, [controller]);

  // The same creation can be achieved by using `useController()` helper:
  // const controller = useController(createPizzaShopController);

  // Using the controller
  const { ordersQuery, addPizza, removePizza, submitCart, submitState } =
    controller;

  // Subscribing to state data and the effect stata
  const orders = useQuery(ordersQuery);
  const isPending = useQuery(submitState.pending);
  const submitError = useObservable(submitState.error$, undefined);

  // Actual rendering should be here.
  return null;
};

© 2021 Mikhail Nasyrov, MIT license

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
2.0.0-beta.00beta
1.1.24latest

Version History

VersionDownloads (Last 7 Days)Published
1.1.24
1.1.11
2.0.0-beta.50
2.0.0-beta.40
2.0.0-beta.30
2.0.0-beta.20
2.0.0-beta.10
2.0.0-beta.00
1.1.00
1.0.10
1.0.00
0.7.20
0.7.10
0.7.00
0.6.00
0.5.20
0.5.10
0.4.10
0.4.00
0.3.30
0.3.20
0.3.10
0.3.00
0.2.20
0.2.10
0.2.00
0.1.00
0.0.80
0.0.70
0.0.60

Package Sidebar

Install

npm i rx-effects-react

Weekly Downloads

5

Version

1.1.2

License

MIT

Unpacked Size

89.1 kB

Total Files

85

Last publish

Collaborators

  • mnasyrov