Last active
October 18, 2019 13:13
-
-
Save simontreny/32a74c621c92ec40e87e24b9a9d67b12 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect, useState } from "react"; | |
import { Observable } from "./observable"; | |
export function useObservable<T>(observable: Observable<T>): T { | |
const [val, setVal] = useState(observable.get()); | |
useEffect(() => { | |
return observable.subscribe(setVal); | |
}, [observable]); | |
return val; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment