Rendyn

Component library

189 components

Agent UI

Code Block

The agent Code Block presents code text, optional highlighted lines and streaming state.

Interactive exampleReact Tailwind CSS

Practical React example

Display a code sample with its filename and a deliberate copy action.

Before you copy and paste

Keep the example in the React rendering environment required by the imported component. Copy components/agents/code-block.tsx and its returned support files from the Code tab; preserve the project-relative paths.

Listed package dependencies: ai, clsx, lucide-react, motion, react, shiki, tailwind-merge.

Use the Code tab for the component files and installation instructions, then adapt the imports in this example to your project.

Display a code sample with its filename and a deliberate copy action

// Usage adapted from beUI's pinned MIT source.
// Copyright (c) 2026 Saurabh Chauhan. See ./LICENSES.md.
"use client";

import { RotateCcw } from "lucide-react";
import { useEffect, useRef, useState } from "react";
import { CodeBlock } from "@/components/agents/code-block";

const LINES = [
  'import { generateText } from "ai";',
  "",
  "export async function summarize(input: string) {",
  "  const { text } = await generateText({",
  '    model: "openai/gpt-5",',
  `    prompt: \`Summarize this clearly: \${input}\`,`,
  "  });",
  "",
  "  return {",
  "    text,",
  "    generatedAt: new Date().toISOString(),",
  "  };",
  "}",
];

function StreamingCodeBlock() {
  const [visibleLines, setVisibleLines] = useState(1);
  const timer = useRef<number | undefined>(undefined);
  const complete = visibleLines === LINES.length;

  useEffect(() => {
    if (visibleLines >= LINES.length) return;
    timer.current = window.setTimeout(
      () => setVisibleLines((value) => value + 1),
      260,
    );
    return () => {
      if (timer.current) window.clearTimeout(timer.current);
    };
  }, [visibleLines]);

  return (
    <CodeBlock
      filename="summarize.ts"
      language="typescript"
      code={LINES.slice(0, visibleLines).join("\n")}
      status={complete ? "complete" : "streaming"}
      highlightLines={[4, 5, 6, 7]}
      maxHeight={224}
    />
  );
}

export function CodeBlockPreview() {
  const [run, setRun] = useState(0);

  return (
    <div className="relative h-[340px] w-full max-w-xl">
      <StreamingCodeBlock key={run} />
      <button
        type="button"
        onClick={() => setRun((value) => value + 1)}
        className="absolute bottom-0 left-0 inline-flex items-center gap-1.5 rounded-full px-2 py-1 text-xs font-medium text-muted-foreground outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring"
      >
        <RotateCcw className="size-3" />
        Replay
      </button>
    </div>
  );
}

Usage example adapted from beUI's pinned MIT source. Retain the source licence notices when copying.

Pass raw code as a string, select the language supported by the imported renderer and keep copy text identical to the code the person expects to receive.

Customization

CodeBlockProps.code
Required; string.
CodeBlockProps.language
Optional; AgentCodeLanguage.
CodeBlockProps.filename
Optional; ReactNode.
CodeBlockProps.status
Optional; CodeBlockStatus.
CodeBlockProps.showLineNumbers
Optional; boolean.
CodeBlockProps.highlightLines
Optional; number[].
CodeBlockProps.maxHeight
Optional; number.
CodeBlockProps.wrap
Optional; boolean.
CodeBlockProps.copyable
Optional; boolean.
CodeBlockProps.onCopy
Optional; () => void | Promise<void>.
CodeBlockProps.className
Optional; string.
AgentCodeProps.code
Required; string.
AgentCodeProps.language
Optional; AgentCodeLanguage.
AgentCodeProps.className
Optional; string.

Integration notes

  • Displaying code does not execute or validate it; review executable examples separately.
  • Check long lines, secrets in copied output and keyboard access to the scrollable region.

Component source: beUI documentation . These examples describe the version imported into Rendyn. Upstream APIs may have changed; retain the source licence notices when adapting the code.

Better with your agent

Give your agent taste.

The best way to use Rendyn is through MCP. Let your agent find the right component, compare previews and bring the source into your project.

All components are free. Sign up only to connect MCP.

Connect to MCP