import { useState } from 'react' ; export function useObjectRef < T extends Record < any , any > > ( init , update , bind ? ) ; export function useObjectRef < T extends Record < any , any > > ( init ) ; export function useObjectRef < T extends Record < any , any > , U extends Record < any , any > > ( init , update , bind ? ) ; export function useObjectRef < T extends Record < any , any > > ( init , bind ? ) ; export function useObjectRef < T extends Record < any , any > > ( init , update , bind ? ) ; export function useObjectRef < T extends Record < any , any > , U extends Record < any , any > > ( init , update ? , bind ? ) { if ( Array . isArray ( update ) ) { bind = update ; update = undefined ; } if ( update === undefined && arguments . length === 1 ) { update = typeof init === 'function' ? init ( ) : init ; } const [ ref ] = useState ( ( ) => { const state = typeof init === 'function' ? init ( ) : init ; if ( bind ) { bindFunctions ( state , bind ) ; } return state ; } ) ; if ( update ) { Object . assign ( ref , update ) ; if ( bind ) { bind = bind . filter ( key => ( key as any ) in ( update as T & U ) ) ; if ( bind . length > 0 ) { bindFunctions ( ref , bind ) ; } } } return ref ; } function bindFunctions < T > ( object , keys ) { for ( const key of keys ) { const value = object [ key ] ; if ( typeof value === 'function' ) { object [ key ] = value . bind ( object ) ; } } }