AppleSauce
    Preparing search index...

    Function useSubscription

    • Accepts an Observable and optional next, error, complete functions. These functions must be in correct order. Use undefined or null for placeholder.

      Subscription will unsubscribe when unmount, you can also unsubscribe manually.

      Note: To make it concurrent mode compatible, the subscription happens after the render is committed to the screen which means even the Observable emits synchronous values they will arrive after the first rendering.

      Note that changes of callbacks will not trigger an emission. If you need that just create another Observable of the callback with [[useObservable]].

      (From v2.0) You can access closure directly inside callback like in useEffect. useSubscription will ensure the latest callback is called.

      (From v2.3.4) when the Observable changes useSubscription will automatically unsubscribe the old one and resubscribe to the new one.

      Note: Due to the design of RxJS, once an error occurs in an observable, the observable is killed. You should prevent errors from reaching observables or catchError in sub-observables. You can also make the observable as state and replace it on error. useSubscription will automatically switch to the new one.

      Type Parameters

      • TInput

        Input value within Observable.

      Parameters

      • input$: Observable<TInput>

        Input Observable.

      • Optionalobserver: PartialObserver<TInput>

        Observer

      Returns MutableRefObject<undefined | Subscription>

    • Type Parameters

      • TInput

        Input value within Observable.

      Parameters

      • input$: Observable<TInput>

        Input Observable.

      • Optionalnext: null | ((value: TInput) => void)

        Notify when a new value is emitted.

      • Optionalerror: null | ((error: any) => void)

        Notify when a new error is thrown.

      • Optionalcomplete: null | (() => void)

        Notify when the Observable is complete.

      Returns MutableRefObject<undefined | Subscription>