react-with-observable
— examples
Use Observables with React declaratively!
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';
const source1$ = of('Hello, world!');
<Subscribe>{source1$}</Subscribe>
const source2$ = interval(1000);
<Subscribe>{source2$}</Subscribe>
const source3$ = interval(1000);
<Subscribe>
{source3$.pipe(
map(val => 10 * val),
scan((acc, val) => acc + val, 0),
map(val => <input value={val} />)
)}
</Subscribe>