DEV Community

Angular Concepts in React: The Async Pipe

Esteban Hernández on September 14, 2019

One of my favorite tools in the Angular framework is the Async pipe. It allows me to render the latest value of an Observable to the screen. The co...
Collapse
 
igorbabkin profile image
Igor Babkin
Collapse
 
spock123 profile image
Lars Rye Jeppesen

React is just not geared towards using Observables, it's totally centered around Promises.

Collapse
 
lysofdev profile image
Esteban Hernández

Agreed, you can however, call the .toPromise() method on the final Observable.

Collapse
 
dcsan profile image
dc

Why does the return function unsubscribe?

Collapse
 
lysofdev profile image
Esteban Hernández

The useEffect hook can optionally return a 'clean-up' function which will be called once the input, in this case the 'ticker' observable changes or if the component unmounts. So, if our Observable where to change then we'd unsubscribe from the first one before subscribing to the new one.