Most of the time you don't need to use this hook directly. The OGCard component already uses it internally to fetch and display Open Graph previews. Use this hook when you need custom rendering or additional control over the fetching logic.
Features
- 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
Basic usage
With custom endpoints
useOgImage hook
With OGCard component
API Reference
useOgData
Return value
useOgImage
useOgImage return value
Required API routes
Image proxying
- Images from the same origin are used directly
- External images are routed through the proxy endpoint
- The proxy adds appropriate cache headers
Error handling
Performance tips
- Conditional fetching: Pass null as URL to skip fetching
- Memoize URLs: Prevent unnecessary refetches
- Cache responses: The proxy endpoint includes cache headers