# Code Block 01

> A simple code block

A shadcn/ui block from the [@shadcnui-blocks](https://shadcnui-blocks.com) registry, listed on [shadcn.exchange](https://shadcn.exchange/r/shadcnui-blocks/code-block-01).

- Page, with a live preview: https://shadcn.exchange/r/shadcnui-blocks/code-block-01
- Screenshot: https://abzjhwgwpdpz7ua5.public.blob.vercel-storage.com/shots/shadcnui-blocks/code-block-01-light-72b9b21ee769a9df.png
- Registry item: https://shadcnui-blocks.com/r/code-block-01.json
- Listed: 2026-10-13, source last changed 2026-10-13

## Install

```bash
npx shadcn@latest add https://shadcnui-blocks.com/r/code-block-01.json
```

Run it in a project that has shadcn/ui set up. It adds the files below and installs what they depend on.

## Dependencies

- npm packages: `shiki`

## Files

### `src/registry/blocks/shared/code-block-01/components/code-block.tsx`

```tsx
"use client";

import { Suspense, use } from "react";
import { codeToHtml } from "shiki";
import { cn } from "@/lib/utils";

const code = `const user = {\n\tname: "John Doe",
\trole: "Frontend Developer",
\texperience: "2+ years",
};

export default function ProfileCard() {
\treturn (
\t\t<div className="p-4 border rounded-lg">
\t\t\t<h2 className="text-lg font-semibold">{user.name}</h2>
\t\t\t<p>{user.role}</p>
\t\t\t<p className="text-sm text-muted-foreground">
\t\t\t\tExperience: {user.experience}
\t\t\t</p>
\t\t</div>
\t);
}
`;

const htmlPromise = codeToHtml(code, {
  lang: "tsx",
  themes: {
    light: "github-light",
    dark: "github-dark-default",
  },
});

function CodeBlockInner() {
  const html = use(htmlPromise);

  return (
    <div className="flex min-h-dvh items-center justify-center px-6">
      <div
        className={cn(
          "grid",
          "[&>pre]:overflow-auto [&>pre]:rounded-lg [&>pre]:border [&>pre]:border-border/50 not-dark:[&>pre]:bg-muted/60! [&>pre]:p-6 [&>pre]:text-sm [&>pre]:leading-[1.6] dark:[&>pre]:border-border/80"
        )}
        dangerouslySetInnerHTML={{ __html: html }}
      />
    </div>
  );
}

export default function CodeBlock() {
  return (
    <Suspense>
      <CodeBlockInner />
    </Suspense>
  );
}
```
