React observing
useSetObserver
useSetObserver
Overview
O useSetObserver
retorna apenas um metodo que pode alterar o valor do observable.
Using this hook is recommended to optimize your application's performance. Since the returned method has no state effects. This way, your component won't have a new render stream every time the set is executed.
useObserver vs useSetObserver
useObserver
always returns a state and a method for changing the state.
Whenever the state change happens, a new rendering stream happens,
this flow can be avoided using this hook.
Definition
function useSetObserver<T>(observable: IObservable<T>): TSetObservableState<T>
Examples
Counter
1import { observe, useSetObserver } from 'react-observing'23const counterObservable = observe(10)45const App = () => {6 const setCounter = useSetObserver(counterObservable)78 return (9 <button onClick={() => setCounter(old => old + 1)}>Add + 1</button>10 )11}