<!-- source-hash: 8cc6f0cadfbca233ed799a57d6b4388c -->
A React hook that fetches markdown-backed legal documents (privacy policy, terms of service, etc.) from a hub API endpoint, with support for SSR/RSC pre-fetched data and manual refetching.

## Key Components

### Interfaces

| Interface | Description |
|-----------|-------------|
| `LegalDocument` | Shape of the fetched document — includes title, markdown content, GitHub sync metadata, and parsed section headings |
| `UseLegalDocsOptions` | Hook configuration — optional `initialData` for SSR hydration and `apiEndpoint` override for reverse-proxy embedders |
| `UseLegalDocsReturn` | Hook return value — `data`, `isLoading`, `error`, and `refetch` |

### `useLegalDocs(docType, options?)`

Core hook that manages fetch lifecycle for a legal document. Key behaviors:

- **Default endpoint:** `/api/legal/<docType>` — overridable via `apiEndpoint`
- **SSR-safe:** When `initialData` is provided, the initial client fetch is skipped entirely
- **`docType` reset guard:** When `docType` changes, stale data is cleared immediately before the new fetch resolves — prevents flash of wrong content in embedders cycling through document types
- **Error handling:** Propagates HTTP errors and empty-content responses as human-readable strings via the `error` state

## Usage Example

```typescript
// Basic client-side fetch
const { data, isLoading, error, refetch } = useLegalDocs('privacy');

// SSR hydration — skip initial client fetch
const { data } = useLegalDocs('terms', {
  initialData: serverFetchedDoc,
});

// Reverse-proxy embedder overriding the endpoint
const { data, isLoading } = useLegalDocs('privacy', {
  apiEndpoint: '/proxy/legal/privacy',
});

if (isLoading) return <Spinner />;
if (error) return <ErrorBanner message={error} onRetry={refetch} />;
return <MarkdownRenderer content={data?.content} />;
```