import { useContext, Context } from 'react'; export function useNonNullableContext(context: Context): NonNullable { const v = useContext(context); if (v == null) throw new Error("Context has not be initialized: " + ( context.displayName ?? "unknown" ) + " context."); return v as NonNullable; }