Fetches a legal document (privacy policy, terms of service, or any markdown-backed legal page) from a hub API endpoint, with SSR/RSC hydration support via optional `initialData`. ## Key Components ### Interfaces - **`LegalDocument`** — Shape of the fetched legal document, mirroring the hub's server-side `LegalDocument` type to avoid server-side import dependencies. - **`UseLegalDocsOptions`** — Hook configuration: optional `initialData` for SSR hydration and `apiEndpoint` override for reverse-proxy embedders. - **`UseLegalDocsReturn`** — Hook return shape: `data`, `isLoading`, `error`, and `refetch`. ### Hook - **`useLegalDocs(docType, options)`** — Core hook. Resolves the effective endpoint (`/api/legal/` by default), manages fetch lifecycle state, resets state on `docType` change, and skips the initial client fetch when `initialData` is provided. ## Usage Example ```typescript import { useLegalDocs } from './use-legal-docs'; // Basic client-side fetch function PrivacyPage() { const { data, isLoading, error, refetch } = useLegalDocs('privacy'); if (isLoading) return

Loading…

; if (error) return

Error: {error}

; return
{data?.content}
; } // With SSR-prefetched data (skips initial client fetch) function TermsPage({ serverData }: { serverData: LegalDocument }) { const { data } = useLegalDocs('terms', { initialData: serverData }); return
{data?.content}
; } // With a proxied endpoint (embedder override) function EmbedPrivacy() { const { data } = useLegalDocs('privacy', { apiEndpoint: '/proxy/legal/privacy', }); return
{data?.content}
; } ``` ## Notes - `docType` is treated as an opaque string and intentionally kept out of `console.error`'s format-string argument to prevent CodeQL `js/tainted-format-string` findings. - State resets on `docType` change prevent stale content from briefly rendering during sequential document loads.