Frontend Blocks
typescript
Advanced
CodeMirror 6 Editor React Component
Syntax-highlighted code editor using CodeMirror 6 with dark theme and language packs.
typescript
import { useEffect, useRef } from "react";
import { EditorView, basicSetup } from "codemirror";
import { javascript } from "@codemirror/lang-javascript";
import { oneDark } from "@codemirror/theme-one-dark";
export function CodeEditor({ value }: { value: string }) {
const ref = useRef<HTMLDivElement>(null);
useEffect(() => {
if (!ref.current) return;
const view = new EditorView({
doc: value,
extensions: [basicSetup, javascript(), oneDark],
parent: ref.current,
});
return () => view.destroy();
}, [value]);
return <div ref={ref} className="rounded-lg overflow-hidden" />;
}
Prerequisites
- codemirror >= 6
- React >= 17
Pro Tips
- → Use EditorState.create() to update value programmatically.
Commercial Licensing
Acquire a production access token or template license for enterprise deployment.
Module Info
- Language
- typescript
- Level
- Advanced
- Read time
- 5 min
- Published
- Oct 2025
- License
- Commercial License
Newsletter
New modules every week, directly to your inbox.
Similar Modules
Copy to Clipboard Button
React component that copies text to clipboard and shows a Copied! confirmation.
typescript
·
Beginner
Framer Motion Fade-In Wrapper
Reusable component that fades any child element in on mount.
typescript
·
Beginner
Compound Component Pattern
Implement a flexible Tabs component using React Context and compound component pattern.
typescript
·
Intermediate