@mvr-studio/obsrvd
v0.0.4
Published
Few kilobytes of a simple observable.
Downloads
1
Readme
Obsrvd
Dead simple Observable.
Installation
yarn add @mvr-studio/obsrvd
Observable
import { Observable } from '@mvr-studio/obsrvd'
const simpleObserver = new Observable<boolean>(false)
const Component = () => {
const [simpleState, setSimpleState] = useState<boolean>(simpleObserver.get())
const handleOnClick = () => {
return simpleObserver.set(true)
}
useEffect(() => {
simpleObserver.subscribe(setSimpleState)
return () => {
simpleObserver.unsubscribe(setSimpleState)
}
}, [])
}
useObservable
import { Observable, useObservable } from '@mvr-studio/obsrvd'
const simpleObserver = new Observable<boolean>(false)
const Component = () => {
const { value } = useObservable(simpleObserver)
// Now, when `simpleObserver` gets set outside the component, `value` will be up to date.
}