Forms
DiffViewer
Line-by-line code and text diff viewer with unified and split layouts and change counts.
import '@reactloom/code-editor/styles.css';
import { DiffViewer } from '@reactloom/code-editor';Examples
Configuration comparison
| 1 | 1 | export const config = { |
| 2 | port: 3000, | |
| 3 | cacheTtl: 60, | |
| 4 | strictMode: false, | |
| 2 | port: 8080, | |
| 3 | cacheTtl: 300, | |
| 4 | strictMode: true, | |
| 5 | 5 | }; |
import { DiffViewer } from '@reactloom/code-editor';
const original = `export const config = {
port: 3000,
cacheTtl: 60,
strictMode: false,
};`;
const modified = `export const config = {
port: 8080,
cacheTtl: 300,
strictMode: true,
};`;
export default function Example() {
return <DiffViewer title="server.config.ts" original={original} modified={modified} />;
}API reference
| Prop | Type | Default |
|---|---|---|
originalrequiredBaseline text. | string | — |
modifiedrequiredUpdated text. | string | — |
titleFile name or comparison heading. | string | — |
modeInitial diff layout. | 'unified' | 'split' | 'unified' |
Keyboard interaction
| Key | Action |
|---|---|
| Tab | Switch focus between Unified and Split layout buttons |
Usage guidelines
Do
- Include a title so users know which file or revision is being compared.
Don’t
- Avoid passing multi-megabyte minified bundles into line diffing.