import { useLayoutEffect } from 'react' ; import { Observable , Observed , OProps } from '../core' ; import { useForceUpdate } from './common' ; /**
 * Subscribe to an observable value, and render whenever it changes.
 */ export function useObserved < T > ( source ) ; export function useObserved < T extends object , P extends keyof T > ( source , prop ) ; export function useObserved ( source , prop ? ) { let target = Observable . from ( source ) ; if ( prop !== undefined && target instanceof OProps ) { target = target . watch ( prop ) ; } const forceUpdate = useForceUpdate ( ) ; useLayoutEffect ( ( ) => { if ( target ) return target . tap ( forceUpdate ) . dispose ; } , [ target ] ) ; return target ? target . get ( ) : source ; }