Skip to content

Instantly share code, notes, and snippets.

@RWalkling
Created February 4, 2020 22:56
Show Gist options
  • Select an option

  • Save RWalkling/048eee2f653cd02113e5d69dd773346c to your computer and use it in GitHub Desktop.

Select an option

Save RWalkling/048eee2f653cd02113e5d69dd773346c to your computer and use it in GitHub Desktop.
function useObserved<TObject>(observable: Observable<TObject>) {
const [state, setState] = useState<TObject>()
useEffect(() => {
const subscription = observable.subscribe(setState)
return () => subscription.unsubscribe()
}, [])
return state
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment