import React , { createContext , useContext } from 'react' ; const OutletContext = createContext < { element ? : React . ReactElement ; } | undefined > ( undefined ) ; export function OutletContextProvider ( { element , children , } ) { return < OutletContext . Provider value = { { element } } > { children } < /OutletContext.Provider>; } export function Outlet ( ) { const outletContext = useContext ( OutletContext ) ; if ( ! outletContext ) { throw new Error ( 'Outlet context not available' ) ; } return outletContext . element || null ; }