MCPcopy Create free account
hub / github.com/47ng/nuqs / CodeBlock

Function CodeBlock

packages/docs/src/components/code-block.client.tsx:15–43  ·  view source on GitHub ↗
({
  code,
  lang = 'tsx',
  compact = false,
  preHighlighted = false,
  ...props
}: CodeBlockProps)

Source from the content-addressed store, hash-verified

13const importHighlight = import('./code-block-highlighter')
14
15export function CodeBlock({
16 code,
17 lang = 'tsx',
18 compact = false,
19 preHighlighted = false,
20 ...props
21}: CodeBlockProps) {
22 const [html, setHtml] = useState<string | null>(null)
23 const { highlight, renderCodeSkeleton } = use(importHighlight)
24 useEffect(() => {
25 ;(async () => {
26 const x = preHighlighted ? code : await highlight(code, lang)
27 setHtml(x)
28 })()
29 }, [code, lang, highlight, preHighlighted])
30 return (
31 <FumaDocsCodeBlock
32 // @ts-expect-error
33 custom={compact ? 'compact' : undefined}
34 {...props}
35 >
36 <Pre
37 dangerouslySetInnerHTML={{
38 __html: html ?? renderCodeSkeleton(code)
39 }}
40 />
41 </FumaDocsCodeBlock>
42 )
43}

Callers

nothing calls this directly

Calls 2

highlightFunction · 0.85
renderCodeSkeletonFunction · 0.70

Tested by

no test coverage detected