import type { Container } from 'ditox' ; import { createContainer } from 'ditox' ; import React , { createContext , ReactElement , ReactNode , useContext , useEffect , useMemo , } from 'react' ; export const DependencyContainerContext = createContext < Container | undefined > ( undefined ) ; /**
 * A callback for binding dependencies to a container
 */ export type DependencyContainerBinder = ( container : Container ) => unknown ; property property export type DependencyContainerParams = { children : ReactNode ; root ? : boolean ; binder ? : DependencyContainerBinder ; } ; category param params . binder param params . root example export function DependencyContainer ( params ) { const { children , root , binder } = params ; const parentContainer = useContext ( DependencyContainerContext ) ; const container = useMemo ( ( ) => { const container = createContainer ( root ? undefined : parentContainer ) ; binder ?. ( container ) ; return container ; } , [ binder , parentContainer , root ] ) ; useEffect ( ( ) => { return ( ) => container . removeAll ( ) ; } , [ container ] ) ; return ( < DependencyContainerContext . Provider value = { container } > { children } < /DependencyContainerContext.Provider>); } category param params . container example export function CustomDependencyContainer ( params ) { const { children , container } = params ; return ( < DependencyContainerContext . Provider value = { container } > { children } < /DependencyContainerContext.Provider>); }