The useOgData hook fetches Open Graph metadata from URLs, including title, description, image, and favicon. It automatically handles image proxying for external sources and provides loading states.
Used in components: OgCard
- Fetches OG metadata from any URL
- Automatic image proxying for CORS-free display
- Loading state management
- Custom API endpoint support
- Companion useOgImage hook for image-only fetching
Fetch and display Open Graph data:
Use custom API routes for fetching and proxying:
For cases where you only need the image:
Combine with the OgCard component for rich previews:
This hook requires two server routes. In a Next.js app, use the ready-made OG route handlers:
Elsewhere, build them on handleOGFetch and handleOGProxy from @once-ui-system/core/server.
The hook calls /api/og/fetch and /api/og/proxy unless told otherwise: by its customFetchUrl and customProxyUrl arguments, or for every caller below it, by OgRoutesProvider:
The hook automatically proxies external images through your server to avoid CORS issues:
- Images from the same origin are used directly
- External images are routed through the proxy endpoint
- The proxy adds appropriate cache headers
The hook handles errors gracefully:
- Conditional fetching: Pass null as URL to skip fetching
- Memoize URLs: Prevent unnecessary refetches
- Cache responses: The proxy endpoint includes cache headers