
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
render-diff-react
Advanced tools
Display Git diffs with beautiful syntax highlighting, extensive customization options, and zero external dependencies for diff functionality
npm install render-diff-react
# or
yarn add render-diff-react
# or
pnpm add render-diff-react
The package includes CSS styles for syntax highlighting. You have several options to include them:
/* Import the styles in your CSS file */
@import "render-diff-react/src/styles.css";
// Import in your JavaScript/TypeScript file
import "render-diff-react/src/styles.css";
import { injectSyntaxHighlightingStyles } from "render-diff-react";
// Call this function once in your app
injectSyntaxHighlightingStyles();
import { syntaxHighlightingCSS } from "render-diff-react";
// Inject the CSS manually
const style = document.createElement("style");
style.textContent = syntaxHighlightingCSS;
document.head.appendChild(style);
import { DiffViewer } from "render-diff-react";
function App() {
const gitDiff = `
diff --git a/src/App.tsx b/src/App.tsx
index 1234567..abcdefg 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -1,3 +1,4 @@
import React from 'react';
+import { useState } from 'react';
function App() {
- return <div>Hello World</div>;
+ const [count, setCount] = useState(0);
+ return <div>Hello World {count}</div>;
}
`;
return (
<div>
<h1>My Git Diff</h1>
<DiffViewer patch={gitDiff} />
</div>
);
}
| Prop | Type | Description |
|---|---|---|
patch | string | The Git diff patch string to render |
| Prop | Type | Default | Description |
|---|---|---|---|
showLineNumbers | boolean | true | Whether to show line numbers |
showFileHeader | boolean | true | Whether to show the file header |
showHunkHeaders | boolean | true | Whether to show the hunk headers |
enableSyntaxHighlighting | boolean | true | Whether to enable syntax highlighting |
syntaxHighlightLanguage | string | "typescript" | The language to use for syntax highlighting |
| Prop | Type | Description |
|---|---|---|
className | string | Custom CSS classes for the main container |
fileClassName | string | Custom CSS classes for the file container |
fileHeaderClassName | string | Custom CSS classes for the file header |
fileNameClassName | string | Custom CSS classes for the file name |
additionsClassName | string | Custom CSS classes for the additions count |
deletionsClassName | string | Custom CSS classes for the deletions count |
splitViewClassName | string | Custom CSS classes for the split view container |
codeLineClassName | string | Custom CSS classes for the code lines |
lineNumberClassName | string | Custom CSS classes for the line numbers |
hunkHeaderClassName | string | Custom CSS classes for the hunk header |
hunkContentClassName | string | Custom CSS classes for the hunk content |
addedLineClassName | string | Custom CSS classes for added lines |
deletedLineClassName | string | Custom CSS classes for deleted lines |
contextLineClassName | string | Custom CSS classes for context lines |
prefixClassName | string | Custom CSS classes for the prefix (+/-/space) |
codeContentClassName | string | Custom CSS classes for the code content |
highlightAddedClassName | string | Custom CSS classes for highlighted additions |
highlightDeletedClassName | string | Custom CSS classes for highlighted deletions |
tokenClassName | string | Custom CSS classes for syntax highlighted tokens |
tokenTextClassName | string | Custom CSS classes for text tokens |
| Prop | Type | Description |
|---|---|---|
theme.backgroundColor | string | Background color for the main container |
theme.borderColor | string | Border color for file containers |
theme.fileHeaderBackgroundColor | string | Background color for file headers |
theme.fileNameColor | string | Text color for file names |
theme.additionsColor | string | Text color for additions count |
theme.deletionsColor | string | Text color for deletions count |
theme.splitViewBackgroundColor | string | Background color for the split view |
theme.lineNumberColor | string | Text color for line numbers |
theme.codeColor | string | Text color for code content |
theme.addedLineBackgroundColor | string | Background color for added lines |
theme.deletedLineBackgroundColor | string | Background color for deleted lines |
theme.hunkHeaderBackgroundColor | string | Background color for hunk headers |
theme.hunkHeaderColor | string | Text color for hunk headers |
theme.highlightAddedBackgroundColor | string | Background color for highlighted additions |
theme.highlightDeletedBackgroundColor | string | Background color for highlighted deletions |
The component comes with built-in styles that work out of the box. For syntax highlighting to work properly, you need to import the CSS styles:
/* Import the syntax highlighting styles */
@import "render-diff-react/src/styles.css";
The component uses a dark theme by default, similar to GitHub's diff view. You can customize all colors and styles using the theme prop and various className props.
The demo showcases all features with live examples and comprehensive documentation.
import { DiffViewer } from "render-diff-react";
function BasicExample() {
const diff = `diff --git a/file.js b/file.js
index 1234567..abcdefg 100644
--- a/file.js
+++ b/file.js
@@ -1,3 +1,4 @@
function hello() {
- console.log("Hello");
+ console.log("Hello World");
+ return true;
}
`;
return <DiffViewer patch={diff} />;
}
import { DiffViewer } from "render-diff-react";
function CustomStylingExample() {
return (
<DiffViewer
patch={diff}
className="my-custom-diff"
fileClassName="border-2 border-blue-500"
theme={{
backgroundColor: "#1a1a1a",
borderColor: "#404040",
fileNameColor: "#ffffff",
additionsColor: "#4ade80",
deletionsColor: "#f87171",
}}
/>
);
}
import { DiffViewer } from "render-diff-react";
function MinimalExample() {
return (
<DiffViewer
patch={diff}
showLineNumbers={false}
showFileHeader={false}
showHunkHeaders={false}
enableSyntaxHighlighting={false}
/>
);
}
import { DiffViewer } from "render-diff-react";
function PythonExample() {
return <DiffViewer patch={pythonDiff} syntaxHighlightLanguage="python" />;
}
The component supports syntax highlighting for all languages supported by refractor, including:
# Install dependencies
npm install
# Start development server
npm run dev
# Build for production
npm run build
# Run tests
npm test
The interactive demo is located in examples/vite-demo/:
cd examples/vite-demo
npm install
npm run dev
Visit http://localhost:3000 to see the demo in action.
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)MIT © Aashish Singhal
This package includes a custom word-level diff implementation that eliminates the need for external diff libraries. The implementation:
diff packageThe package includes custom SVG icons instead of external icon libraries:
FAQs
A React component for rendering Git diffs with syntax highlighting
The npm package render-diff-react receives a total of 0 weekly downloads. As such, render-diff-react popularity was classified as not popular.
We found that render-diff-react demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.