1.1.1 • Published 9 months ago

rx-effects-react v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

RxEffects: rx-effects-react

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

1.1.1

9 months ago

1.1.0

1 year ago

1.0.1

1 year ago

2.0.0-beta.2

1 year ago

2.0.0-beta.1

1 year ago

2.0.0-beta.0

1 year ago

2.0.0-beta.5

1 year ago

2.0.0-beta.4

1 year ago

2.0.0-beta.3

1 year ago

1.0.0

1 year ago

0.7.2

2 years ago

0.7.1

2 years ago

0.7.0

2 years ago

0.6.0

2 years ago

0.5.2

2 years ago

0.5.1

2 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.3.3

3 years ago

0.3.2

3 years ago

0.3.0

3 years ago

0.3.1

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.0

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago