First steps
This page mirrors the RxJS overview — the same progression of examples, but inside React components. Where the RxJS guide contrasts plain JavaScript with observables, we contrast React + RxJS wired by hand with react-rx. If observables themselves are new to you, skim that guide first; react-rx assumes the basics.
Counting clicks
Normally, bridging a stream into React means owning the whole lifecycle yourself: a Subject for the events, a useEffect to subscribe, a mirrored useState to hold the latest value, and an unsubscribe on unmount. Every copy of this is a chance for a leak or a stale closure:
Using react-rx, the component just reads the stream. The count state lives in the pipe — scan works like reduce for arrays — and the hook owns subscription, initial value, and teardown:
The bridge boilerplate is gone, and something subtler improved too: the state can no longer be mutated from anywhere else. The only way to change the count is to emit a click.
Flow
RxJS has a whole range of operators that control how events flow through your streams. In vanilla React, “count at most one click per second” means refs, timestamps, and an easy-to-botch comparison. In a stream it is one operator:
Values
You can transform the values passing through. Here every click contributes its pointer’s x position to a running sum — map plucks the coordinate, scan accumulates it, and the component renders whatever comes out:
Where to next
Basic state rebuilds the useState docs examples on streams, and Timers & time ago shows where streams beat hooks hardest. For choosing between the hooks you just saw, read which hook should I use?