'use client'; import { useMemo } from 'react'; import { CopyButton } from '@djangocfg/ui-core/components'; import { JsonTree } from '../../../../../../../data/JsonTree'; interface ResponseBodyProps { example: string; contentType?: string; } /** Render the example response body: content-type strip + copy button * header, then the JSON tree (falling back to a ``
`` if the
 *  example isn't valid JSON — sampler occasionally emits non-JSON for
 *  exotic content types). */
export function ResponseBody({ example, contentType }: ResponseBodyProps) {
    // Parse once and cache. ``example`` is pre-stringified by the
    // sampler; JsonTree wants a live object to render nodes with proper
    // folding, so we flip it back here.
    const parsed = useMemo(() => {
        try {
            return JSON.parse(example);
        } catch {
            return null;
        }
    }, [example]);

    return (
        
{contentType ?? 'application/json'} Copy
{parsed != null ? ( // Docs longread is space-constrained: no toolbar (Copy // lives on the row header above), no border (host owns // it), shallow auto-expand. ) : (
                    {example}
                
)}
); }