Categories
TypeScript Answers

How to return an empty Observable with Rxjs?

Spread the love

Sometimes, we want to return an empty Observable with Rxjs.

In this article, we’ll look at how to return an empty Observable with Rxjs.

How to return an empty Observable with Rxjs?

To return an empty Observable with Rxjs, we can use EMPTY or of.

For instance, we write

import { EMPTY, empty, of } from "rxjs";

EMPTY;
of({});

to import EMPTY which is an empty observable.

We can also call of with an empty object to return an empty observable.

Conclusion

To return an empty Observable with Rxjs, we can use EMPTY or of.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *