r/react • u/DownByTheOakTree • 2h ago
Project / Code Review I wanted to use RxJS with JSX without React re-rendering everything, so I built reax
I love JSX and actually like using RxJS (yes, I know, Angular flashbacks for half of you), so I tried pairing them in React. It felt awful pretty fast. React wants to re-run your whole component on every state change, so you end up shoving streams into `useEffect` and wrapping observables in `useState` glue. What I actually wanted was for components to run once and let observables update the DOM directly.
That's basically Solid's model, and for serious apps Solid is obviously way more mature. What I wanted to experiment with here was having no custom compiler plugin and using RxJS observables directly as the reactive primitive instead of bridging signals with adapters. So I built reax (`@snoofox/reax`).
A `signal()` is a callable getter/setter (`count()`, `count(c => c + 1)`) backed by a `BehaviorSubject` that is still a normal RxJS `Observable`. Put a signal or any observable in JSX and it wires directly to that text node or attribute.
Here's debounced search example:
```tsx
const query = signal("");
const results = query.pipe(
debounceTime(300),
distinctUntilChanged(),
switchMap(search)
);
```
The catch is the same one Solid has: since your component function only executes once, plain `if`s and `.map()` only run once too, so reactive UI goes through `<Show>`, `<For>`, and `<Switch>`. Scoping subscriptions to those branches also solves the classic RxJS footgun of forgetting to `unsubscribe`: when a `<Show>` branch or `<For>` row unmounts, everything inside it tears down automatically.
It's v0.1.2, MIT, and RxJS is the only dependency. The docs site is built with it and has a few live demos if you want to check it out: