import { Context, use } from "react"; export function useSafeContext( context: Context, name: string, ): NonNullable { const value = use(context); if (!value) throw new Error(`${name}Context not found`); return value; }