Comments (2)
Something like this?
import { pipeWith } from 'pipe-ts';
import { useObservable } from 'rxjs-hooks';
import { RestrictArray } from 'rxjs-hooks/dist/cjs/type';
import * as Rx from 'shared/facades/rx';
/** `useObservable` is designed for creating state and using that in the component, but most of the
* time we just want to run side effects. This is a specialised version of `useObservable` that
* handles those use cases. https://github.com/LeetCode-OpenSource/rxjs-hooks/issues/98 */
export const useObservableSideEffect = <Inputs>(
runSideEffects: (inputs$: Rx.Observable<RestrictArray<Inputs>>) => Rx.Observable<unknown>,
inputs: RestrictArray<Inputs>,
): void => {
useObservable(
(_state$, inputs$) => pipeWith(inputs$, runSideEffects, Rx.ignoreElements()),
undefined,
inputs,
);
};
from rxjs-hooks.
In Redux-Observable, for side-effects, I always use ignoreElements
.
This is a matter of auto-returning the value that goes through the stream. I wrote an article about a possible alternative, but I dunno if that's the intention of the library. It's add more complexity.
https://itnext.io/the-best-practice-anti-pattern-5e8bd873aadf?source=rss----5b301f10ddcd---4
Having a hook for side-effects makes more sense because that's the same as useEffect
today.
from rxjs-hooks.
Related Issues (20)
- useEventCallback is not working with react 18 HOT 3
- Shows "difficulty.easy" in SQL section instead of Easy,Medium and Hard
- 为什么我写了依赖,但是不管用呢,界面并不会更新啊 HOT 2
- Feature request: add support for error handling and tap option HOT 1
- `useObservable` state generic is incorrectly inferred HOT 1
- Question about useEventCallback. HOT 1
- Passing custom values into `useEventCallback` callback HOT 1
- Feature request: useObservable to return the instant value on Component initialize if Observable has sync value HOT 1
- This project is alive? HOT 4
- An in-range update of @types/lodash is breaking the build 🚨 HOT 7
- An in-range update of husky is breaking the build 🚨 HOT 5
- An in-range update of sinon is breaking the build 🚨 HOT 2
- An in-range update of webpack-cli is breaking the build 🚨 HOT 2
- An in-range update of ts-jest is breaking the build 🚨 HOT 1
- useEventCallback stop working with RJXS.ajax HOT 2
- An in-range update of tslint-react is breaking the build 🚨 HOT 1
- Bug: Emit same object will not trigger re-render HOT 3
- I cant calc the dom size HOT 4
- Suggestion: use object for `input` instead of tuple HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rxjs-hooks.