react-with-observable — examples

Use Observables with React declaratively!

Before you start

The following examples are created with RxJS. Make sure to include the Symbol.observable polyfill before you start:

import 'symbol-observable';
import { of, interval, BehaviorSubject } from 'rxjs';
import { map, startWith, scan } from 'rxjs/operators';
import { ajax } from 'rxjs/ajax';
import { Subscribe } from 'react-with-observable';

First example

const source1$ = of('Hello, world!');
<Subscribe>{source1$}</Subscribe>

Timer example

const source2$ = interval(1000);
<Subscribe>{source2$}</Subscribe>

Operators example

const source3$ = interval(1000);
<Subscribe>
  {source3$.pipe(
    map(val => 10 * val),
    scan((acc, val) => acc + val, 0),
    map(val => <input value={val} />)
  )}
</Subscribe>

Contacts list example