I have a scenario where after saving form data, user will see a notification in react component. I don't want to save the data in redux store. How to do this using redux observable and react?
Asked
Active
Viewed 113 times
-1
-
I assume that the solution would depend mainly on the react component that you are using for notifications. Example: `react-toastify` exports a function `toast` that allows to show notifications via a side effect directly inside your epic (efter saving the form data). If you need a more specific answer just add some more info about your problem (the relevant part of your epic and your notifications react component) – kruschid Mar 13 '21 at 15:20
1 Answers
1
If you are asking how to turn a promise into an observable, you can use the from
operator. In your scenario, you can try the code below.
const saveObservable$ = from(httpSvc.save(reqBody);
saveObservable$.pipe(
switchMap(saveMessage => from(notificationService.showNotificataion(saveMessage))),
take(1) // this will only take the first stream so we don't get memory leaks after subscribing.
).subscribe();

Paul
- 460
- 2
- 7
-
your solution would work with angular but he is asking about redux-observable ;-) – kruschid Mar 13 '21 at 21:24
-
Ok but this solution actually is rxjs specific and has nothing to do with Angular. – Paul Mar 13 '21 at 23:17