Skip to content

Am I using observable-hooks correctly? #134

Answered by crimx
nareshbhatia asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, I would not recommend using BehaviorSubject for state management in React. There are better options like Signals. RxJS as far as I am concerned is more suitable for orchestrating sequence of asynchronous operations.

    // Subscribe to the data$ observable
    const data$Subscription = data$.subscribe({
      next: (response) => {
        movies$.next(response.movies as Movie[]);
        loading$.next(false);
      },
      error: (error: Error) => {
        error$.next(error.message);
        loading$.next(false);
      },
    });

This is not a very idiomatic way to write RxJS. In RxJS you normally consume the value at the end of a flow by subscribing it. If you want to change the va…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@nareshbhatia
Comment options

@crimx
Comment options

@nareshbhatia
Comment options

@crimx
Comment options

Answer selected by crimx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants