react-codemirror

react-codemirror

CodeMirror 6 component for React

Description

Dropping a real code editor into a React page sounds easy until you wire CodeMirror 6 by hand: creating and destroying the EditorView, keeping controlled state in sync, and stopping the cursor from jumping on every re-render. react-codemirror does that plumbing for you. A single <CodeMirror /> component takes value and onChange, and you get syntax highlighting, line numbers and folding out of the box.

It pulls in more than 7.6 million npm downloads a week and sits behind plenty of web IDEs, SQL consoles, low-code builders and config panels. Beyond the component, the repo ships dozens of ready themes, language packs and small extensions, so most common needs are already covered.

Features



Component or hook: use the <CodeMirror /> component for the simple case, or switch to the useCodeMirror hook when you want the editor instance and container ref yourself.

Dozens of themes: Dracula, GitHub, Material, Nord, VS Code and more each live in their own npm package, and an online theme editor lets you tune colors and export the code.

Language support: language extensions cover JavaScript, TypeScript, JSX, Python, SQL, Markdown, Rust and well over a hundred others.

Diff view: react-codemirror-merge gives a side-by-side merge view for version comparison and review screens.

Handy extensions: color swatches, clickable links, relative line numbers, zebra stripes, @-mention completion and event hooks, each pulled in only when you need it.

Written in TypeScript: full type definitions, so your editor suggests the available options while you configure it.

Works without a bundler: a prebuilt bundle lets you load it straight into a plain web page.