import { Container , Token } from 'ditox' ; import { useContext , useMemo } from 'react' ; import { DependencyContainerContext } from './DependencyContainer' ; category export function useDependencyContainer ( mode ) ; category export function useDependencyContainer ( mode ? ) ; internal export function useDependencyContainer ( mode ? ) { const container = useContext ( DependencyContainerContext ) ; if ( ! container && mode === 'strict' ) { throw new Error ( 'Container is not provided by DependencyContainer component' ) ; } return container ; } category export function useDependency < T > ( token ) { const container = useDependencyContainer ( 'strict' ) ; const value = useMemo ( ( ) => container . resolve ( token ) , [ container , token ] ) ; return value ; } category export function useOptionalDependency < T > ( token ) { const container = useDependencyContainer ( ) ; const value = useMemo ( ( ) => container ?. get ( token ) , [ container , token ] ) ; return value ; }