import { useEffect , useRef } from 'react' ; import { UserDataService } from '@cloudbeaver/core-authentication' ; import { useService } from '@cloudbeaver/core-di' ; export function useUserData < T > ( key , defaultValue , onUpdate , validate ? ) { const userDataService = useService ( UserDataService ) ; const ref = useRef < T | null > ( null ) ; const data = userDataService . getUserData ( key , defaultValue , validate ) ; useEffect ( ( ) => { if ( ref . current !== data ) { ref . current = data ; onUpdate ( data ) ; } } ) ; return data ; }