https://github.com/mvr-studio/obsrvd
https://github.com/mvr-studio/obsrvd
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/mvr-studio/obsrvd
- Owner: mvr-studio
- License: mit
- Created: 2023-04-01T07:02:39.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-04-27T14:39:36.000Z (about 2 years ago)
- Last Synced: 2025-01-27T10:43:38.761Z (4 months ago)
- Language: TypeScript
- Size: 163 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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.
}
```