I need to get data from redux store to make another api call and the response needs to be saved to the store. How can we avoid callback
hell in this case.
Following is the code snippet which subscribes to the observable.
Store
this.user$ = this.store.select('user');
this.dataStore$ = this.store.select('dataStore')
Callback Hell
this.user$.subscribe((user: any) => {
this.abcService.getData(user.id).subscribe((data:any) => {
this.data = data;
this.dataStore$.dispatch(abcAction(data));
}
}
How to avoid this above callbacks. In promise world we could easily chain promises. Since observables
are not chainable, how do we avoid nested callbacks and what is the best way to write above code. Would like to know how best rxjs operators can be applied.
Any help is greatly appreciated.