Skip to content

mvr-studio/obsrvd

Repository files navigation

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.
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published