---
title: "Code Block"
description: "Streaming code with fixed line numbers and wrap."
documentation: "https://beui.dev/react-native/code-block"
markdown: "https://beui.dev/react-native/code-block.md"
---

# Code Block

> Streaming code with fixed line numbers and wrap.

React Native component for Expo, from beUI Native. Group: AI agents. Variants: 1.

## Install

Set up beUI Native once per app first: https://beui.dev/docs/native-setup.md

```bash
npx beui-native add code-block
```

Or copy the source by hand and install its libraries:

```bash
npx expo install prism-react-renderer react-native-reanimated react-native-svg react-native-worklets
npm install uniwind tailwindcss
```

## Links

- Source: https://github.com/starc007/beui-native/tree/main/src/components/code-block
- Registry JSON with every file: https://beui.dev/native/r/code-block
- Open in Expo Go: exp://u.expo.dev/93a3a95c-6dc2-4adb-b57c-efbecf859f25/--/code-block?runtime-version=exposdk%3A58.0.0&channel-name=production
- Web version: https://beui.dev/components/agents/code-block.md

## README

### Code Block

Native port of [beUI Code Block](https://beui.dev/components/agents/code-block): highlighted code that an agent writes line by line.

```tsx
import * as Clipboard from "expo-clipboard";
import { CodeBlock } from "./src";

<CodeBlock
  code={code}
  filename="summarize.ts"
  language="typescript"
  status={writing ? "streaming" : "complete"}
  highlightLines={[4, 5]}
  onCopy={() => Clipboard.setStringAsync(code)}
/>
```

#### Behavior

- Highlighting covers TypeScript, TSX, JavaScript, JSX, JSON, Bash, Python, Swift, Kotlin, Go, Rust, SQL, CSS, YAML and Markdown, in colors that follow light and dark mode. Use `"text"` for none.
- While `status` is `streaming`, the header says "Writing" and the view follows new lines. It says "Ready" once complete.
- `highlightLines` tints whole rows, numbers included. `showLineNumbers` turns the numbers off.
- Copy appears when you pass `onCopy` and shows a check for 1600 ms.

#### Better on a phone

- Line numbers stay put while long lines scroll sideways, so you never lose track of which line you're on.
- A button in the header wraps long lines instead, and back. Start wrapped with `wrap`.
- Following stops the moment you drag up to read and resumes when you return to the end.
- Highlighting runs in plain JavaScript as the code arrives, so streamed lines never flash back to plain text.

#### Accessibility

- The status is a polite live region, and the block is marked busy while streaming.
- The copy and wrap buttons have names, and wrap reports whether it's on.
- Reduced motion, or `disableAnimation`, follows without smooth scrolling and holds the spinner still.

Copy this directory, `hooks/use-reduced-motion.ts`, `primitives/agent-icons.tsx`, `primitives/code-tokens.ts`, `primitives/spin-glyph.tsx`, `styles/motion.ts`, and the semantic tokens in `styles/theme.css`. It uses `react-native-svg` and `prism-react-renderer` for tokenizing.
