React observing
useObserverValue
useObserverValue
Overview
The useObserverValue allows easy subscribing to an observable object.
It automates all the manual process that would be needed.
The useObserverValue is very similar to the useObserver hook.
However, it only returns the state and not a function to change that state.
useObserver vs useObserverValue
The useObserver hook by default returns a state and a function to change it.
When you only want the state value and are not interested in changing it, it is recommended to use this method.
It is simpler and makes the application more optimized.
Definition
function useObserverValue<T>(observable: IObservable<T>): TExamples
Counter
1import { observe, useObserverValue } from 'react-observing'23const counterObservable = observe(10)45const App = () => {6 const counter = useObserverValue(counterObservable)78 return (9 <p>Counter is in {counter}</p>10 )11}