11'use client' ;
22
3- import React , { type ReactNode , createContext , useState } from 'react' ;
3+ import React , { type ReactNode , createContext , useEffect , useState } from 'react' ;
44
55import { Separator } from '@/components/ui/separator' ;
66import { cn } from '@/lib/utils' ;
@@ -72,6 +72,11 @@ export function APIItem({
7272 value,
7373} : Item ) {
7474 const { listType, name : contextName } = React . useContext ( APIContext ) ;
75+ const [ mounted , setMounted ] = useState ( false ) ;
76+
77+ useEffect ( ( ) => {
78+ setMounted ( true ) ;
79+ } , [ ] ) ;
7580
7681 const id = contextName
7782 ? `${ contextName } -${ listType ? `${ listTypeToId [ listType ] } -` : '' } ${ name } `
@@ -80,6 +85,42 @@ export function APIItem({
8085 . replace ( / ^ - | - $ / g, '' )
8186 : undefined ;
8287
88+ // During SSR or when not mounted, render a simpler version
89+ if ( ! mounted ) {
90+ return (
91+ < li id = { id } className = "scroll-mt-20 py-4" >
92+ < h4 className = "relative py-2 text-start leading-none font-semibold tracking-tight" >
93+ { id && (
94+ < a
95+ className = { cn (
96+ 'opacity-0 hover:opacity-100'
97+ ) }
98+ onClick = { ( e ) => e . stopPropagation ( ) }
99+ href = { `#${ id } ` }
100+ >
101+ < div className = "absolute top-2 -left-5 pr-1 leading-none" >
102+ < Icons . pragma className = "size-4 text-muted-foreground" />
103+ </ div >
104+ </ a >
105+ ) }
106+ < span className = "font-mono text-sm leading-none font-semibold" >
107+ { name }
108+ </ span >
109+ { required && (
110+ < span className = "font-mono text-xs leading-none text-orange-500" >
111+ { ' ' }
112+ REQUIRED
113+ </ span >
114+ ) }
115+ < span className = "text-left font-mono text-sm leading-none font-medium text-muted-foreground" >
116+ { ! required && optional && ' optional' } { type }
117+ </ span >
118+ </ h4 >
119+ < div className = "pt-2 pb-0" > { children } </ div >
120+ </ li >
121+ ) ;
122+ }
123+
83124 return (
84125 < AccordionItem className = "border-none select-text" value = { value ?? name } >
85126 < AccordionTrigger className = "group p-0 hover:no-underline" >
@@ -217,6 +258,11 @@ export function APIList({
217258
218259 const [ values , setValues ] = useState < string [ ] > ( defaultValues ) ;
219260 const [ expanded , setExpanded ] = useState ( ! collapsed ) ;
261+ const [ mounted , setMounted ] = useState ( false ) ;
262+
263+ useEffect ( ( ) => {
264+ setMounted ( true ) ;
265+ } , [ ] ) ;
220266
221267 if ( listType === 'returns' && ! childCount ) return null ;
222268
@@ -290,7 +336,7 @@ export function APIList({
290336 { /* {listType !== 'returns' && <Separator />} */ }
291337 < Separator />
292338
293- { hasItems ? (
339+ { hasItems && mounted ? (
294340 < Accordion
295341 className = "w-full space-y-2 py-4"
296342 value = { values }
@@ -304,6 +350,12 @@ export function APIList({
304350 } ) ;
305351 } ) }
306352 </ Accordion >
353+ ) : hasItems && ! mounted ? (
354+ < div className = "py-4" >
355+ { React . Children . map ( children , ( child , i ) => {
356+ return child ;
357+ } ) }
358+ </ div >
307359 ) : childCount > 0 ? (
308360 children
309361 ) : (
0 commit comments