Skip to content
Middle+6 views

What is the startWith operator used for?

Practice

AI answer

In RxJS, the startWith operator adds the specified values to the beginning of an Observable: they are emitted as soon as someone subscribes, before the values from the source Observable. This is useful, for example, for setting an initial state or form value.

source$.pipe(startWith(initialValue))

The subscriber first receives initialValue, then the values from source$. The operator does not change the source stream itself.