Skip to main content

useLegalPage

Loads one document from the legal-pages CMS collection.

When to use it​

Signed-out reads default to allowed unless explicitly overridden; an undefined slug disables the lookup.

Setup​

Call it from a client-side React component below OvokProvider so it uses the client configured at that provider boundary.

Hook arguments​

ArgumentTypeDetails
slugstring | undefinedLegal-page slug; undefined disables the lookup.
options (optional)OvokCmsOptionsCMS options; signed-out access defaults to true.

TypeScript signature​

(slug: string | undefined, options?: OvokCmsOptions): OvokRequestState<OvokCmsDocument>

Request state​

The response payload is OvokCmsDocument. A successful empty result, a failed request, and a request that has not returned data are distinct states.

FieldMeaning
dataLatest successful response, or undefined before one is available.
loadingWhether the request is in progress.
errorRequest error as an Error, or undefined when no request has failed.
reloadRepeats the request with the current arguments.

Request behavior​

The hook loads when its required inputs are available and reloads when those inputs change. Use reload for an explicit refresh; render loading, error, and successful no-result states separately.

Example​

Handle the hook's loading and error states before rendering the result.

import { useLegalPage } from '@ovok/core';

export function LegalPageExample({ slug, options }: { slug: Parameters<typeof useLegalPage>[0]; options?: Parameters<typeof useLegalPage>[1] }) {
const { data, loading, error, reload } = useLegalPage(slug, options);
if (loading) return <p>Loading…</p>;
if (error) return <p role="alert">{error.message}</p>;
return <section><button onClick={reload}>Reload</button><pre>{JSON.stringify(data, null, 2)}</pre></section>;
}