You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We are forced to return an Observable of a certain type (State), when the type doesn't matter to us, since the result is not being used outside of the hook. We need to do mergeMapTo(EMPTY) at the end of the chain, to satisfy the return type.
We are forced to provide an initial state, but again we are not using State here.
What do you think about another hook which is specifically designed for this use case, to avoid the problems above?
import{pipeWith}from'pipe-ts';import{useObservable}from'rxjs-hooks';import{RestrictArray}from'rxjs-hooks/dist/cjs/type';import*asRxfrom'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 */exportconstuseObservableSideEffect=<Inputs>(runSideEffects: (inputs$: Rx.Observable<RestrictArray<Inputs>>)=>Rx.Observable<unknown>,inputs: RestrictArray<Inputs>,): void=>{useObservable((_state$,inputs$)=>pipeWith(inputs$,runSideEffects,Rx.ignoreElements()),undefined,inputs,);};
Sometimes we want to use an observable not to create state but rather just to perform side effects.
This is possible using
useObservable
:… but it's a bit awkward for a few reasons:
Observable
of a certain type (State
), when the type doesn't matter to us, since the result is not being used outside of the hook. We need to domergeMapTo(EMPTY)
at the end of the chain, to satisfy the return type.State
here.What do you think about another hook which is specifically designed for this use case, to avoid the problems above?
I'm sure we can find a better name… 😄
The text was updated successfully, but these errors were encountered: