Skip to content
TrademarkTrademark
Docs
Hooks

useOgData

Updated: February 22, 2026
View on GitHub

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

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

Fetch and display Open Graph data:

With custom endpoints

Use custom API routes for fetching and proxying:

useOgImage hook

For cases where you only need the image:

With OgCard component

Combine with the OgCard component for rich previews:

API Reference

useOgData

Type
Default
url
stringnull
—
customFetchUrl
stringOgRoutesProvider's fetch, or '/api/og/fetch'
customProxyUrl
stringOgRoutesProvider's proxy, or '/api/og/proxy'

Return value

useOgImage

Type
Default
url
stringnull
—
customFetchUrl
stringOgRoutesProvider's fetch, or '/api/og/fetch'
customProxyUrl
stringOgRoutesProvider's proxy, or '/api/og/proxy'

useOgImage return value

Required API routes

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:

Image proxying

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

Error handling

The hook handles errors gracefully:

Performance tips

  • Conditional fetching: Pass null as URL to skip fetching
  • Memoize URLs: Prevent unnecessary refetches
  • Cache responses: The proxy endpoint includes cache headers
Edit this page on GitHub