An open API service indexing awesome lists of open source software.

https://github.com/mvr-studio/obsrvd


https://github.com/mvr-studio/obsrvd

Last synced: 2 months ago
JSON representation

Awesome Lists containing this project

README

        

# Obsrvd

Dead simple Observable.

## Installation

```sh
yarn add @mvr-studio/obsrvd
```

## Observable

```tsx
import { Observable } from '@mvr-studio/obsrvd'

const simpleObserver = new Observable(false)

const Component = () => {
const [simpleState, setSimpleState] = useState(simpleObserver.get())

const handleOnClick = () => {
return simpleObserver.set(true)
}

useEffect(() => {
simpleObserver.subscribe(setSimpleState)
return () => {
simpleObserver.unsubscribe(setSimpleState)
}
}, [])
}
```

## useObservable

```tsx
import { Observable, useObservable } from '@mvr-studio/obsrvd'

const simpleObserver = new Observable(false)

const Component = () => {
const { value } = useObservable(simpleObserver)
// Now, when `simpleObserver` gets set outside the component, `value` will be up to date.
}
```