Dead simple Observable.
yarn add @mvr-studio/obsrvd
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)
}
}, [])
}
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.
}