import React , { useEffect , useState , ComponentType } from "react" ; param props . target param props . targetProps param props . onLoading example export function LazyComp < T = { } > ( props ) { let [ Comp , setComp ] = useState < { default : ComponentType < T > ; } > ( null ) ; useEffect ( ( ) => { ( async ( ) => { const comp = await props . target ( ) ; if ( comp . default != null ) { setComp ( comp ) ; } else { throw new Error ( " 'target' props of LazyComp must be default export ReactNode" ) ; } } ) ( ) ; } , [ ] ) ; return Comp ? < Comp . default { ... props . targetProps } / > : ( props . onLoading ?? < div > < /div>); }