1 "use client"
2
3 import React from "react"
4 import { ReferenceContent } from "docs-ui"
5 import type { DocPage } from "types"
6 import { Loading, swrFetcher } from "docs-ui"
7 import useSWR from "swr"
8 import { config } from "../../config"
9 import { notFound } from "next/navigation"
10 import { Suspense } from "react"
11
12 type ReferenceJSONProps = {
13 slug: string[]
14 }
15
16 /**
17 * Client renderer for references served as the JSON doc-model. Fetches the
18 * `DocPage` from the references API and renders it with `ReferenceContent`
19 * (no MDX serialization / hydration).
20 */
21 export const ReferenceJSON = ({ slug }: ReferenceJSONProps) => {
22 const { data, error, isLoading } = useSWR<
23 DocPage | { error: { name: string; message: string } }
24 >(`${config.basePath}/api/references/${slug.join("/")}`, swrFetcher)
25
26 if (isLoading || !data) {
27 return <Loading />
28 }
29
30 if ("error" in data || error) {
31 return notFound()
32 }
33
34 return (
35 <Suspense fallback={<Loading />}>
36 <div className="animate animate-fadeIn">
37 <ReferenceContent page={data} />
38 </div>
39 </Suspense>
40 )
41 }