DEV Community

Cover image for When and how to use mergeMap
Jozsef
Jozsef

Posted on

When and how to use mergeMap

If a developer uses Angular without knowing the power of RxJS the code can turn into a huge mass very fast.

When the inner observable needs a value from the outer observable, we can and must use mergeMap!

As a result, we not just gonna have nicer and more readable code, but we can follow the async pipe pattern.
It has also performance advantages if the outer event triggers twice then the first execution will be canceled.

With mergeMap

with mergeMap

Without mergeMap

without mergeMap

I am a Full-stack [Angular, Java] contractor/freelancer developer, if you would like to contact me here is my website !

You can find me on LinkedIn as well.

Top comments (0)