reactivooks
v1.0.6
Published
Reactive hooks, using rxjs
Downloads
2
Maintainers
Readme
Install
npm i reactivooks
Usage example
import { click$, open$ } from "./store"
import { useBehaviorSubject, useSubject } from "reactivooks"
export default function App() {
return (
<div>
<Hello/>
<World/>
</div>
)
}
const Hello = () => {
const fireClick = useSubject(click$)
const [ open, setOpen ] = useBehaviorSubject(open$)
return (
<div>
<Hello/>
<World/>
</div>
)
}
const Hello = () => {
const fireClick = useSubject(clicking)
const handleClick = () => fireClick('Tell everyone I was clicked!')
return (
<div>
<button onClick={handleClick}>Click me</button>
</div>
)
}
const World = () => {
useSubject(click$, message => {
console.log('message:', message)
})
const [ open ] = useBehaviorSubject(open$)
return (
<div>
</div>
)
}
./store.ts
import { BehaviorSubject, Subject } from "rxjs"
export const click$ = new Subject()
export const open$ = new BehaviorSubject(false)