Closed pastelmind closed 2 years ago
React-RxJS is more suited for global state. We already have createSignal
that's used to handle user input. Your example would become:
import { createSignal } from '@react-rxjs/utils';
const [observable$, handler] = createSignal();
// Compose observable$ to create other observables
const MyComponent = () => {
return <button onClick={handler}>
Click me
</button>
}
Your proposal is quite close to the approach https://github.com/crimx/observable-hooks are using.
React's basic data flow is, roughly:
Currently, react-rxjs only handles part B. This proposal discusses part A.
When using React and RxJS, there are two ways of handling events.
fromEvent
directly on DOM elements, working outside React's event systemNeither is clearly desirable. Instead, what if react-rxjs provided a helper that creates event handlers using RxJS operators?
Here is a tentative type signature for such a helper:
E.g.
(We could flesh out the details of
useHandler()
later)This would provide a better story for React devs who want to use RxJS (or vice versa).