import { useMatchLoaderData } from './providers' ; import type { LoaderData } from '../root' ; import { handle } from '../root' ; export const useRootData = ( ) => useMatchLoaderData < LoaderData > ( handle . id ) ; export function useUser ( ) { const { user } = useRootData ( ) ; if ( ! user ) throw new Error ( 'User is required when using useUser' ) ; return user ; }