You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{useHandler}from'@react-rxjs/utils'constMyComponent=()=>{const[handler,observable$]=useHandler<React.MouseEvent>(// This callback creates an observable// When the component mounts, the observable is subscribed automatically.// When the component unmounts, the observable is unsubscribed.(event$)=>event$.pipe(/* ... */),[/* dependency array */])// Here, we can compose observable$ to create another observablereturn(<buttononClick={handler}>
Click me
</button>)}
(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).
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 observablesconstMyComponent=()=>{return<buttononClick={handler}>Clickme</button>}
Activity
voliva commentedon May 9, 2022
React-RxJS is more suited for global state. We already have
createSignalthat's used to handle user input. Your example would become:Your proposal is quite close to the approach https://github.com/crimx/observable-hooks are using.