@uiw/react-codemirror vs react-codemirror2
Integrating Code Editors in React Applications
@uiw/react-codemirrorreact-codemirror2

Integrating Code Editors in React Applications

Both @uiw/react-codemirror and react-codemirror2 serve as React bindings for the CodeMirror text editor, but they target different major versions of the underlying engine. @uiw/react-codemirror is designed for CodeMirror 6, which is a complete rewrite focusing on modularity and performance. react-codemirror2 wraps CodeMirror 5, a mature and stable version that is now in maintenance mode. This distinction affects how you configure extensions, handle themes, and manage editor state within your application.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
@uiw/react-codemirror02,200820 kB1727 days agoMIT
react-codemirror201,70471.5 kB947 months agoMIT

@uiw/react-codemirror vs react-codemirror2: Architecture and API Compared

Both packages allow you to embed the CodeMirror editor into React applications, but they sit on top of different core engines. @uiw/react-codemirror uses CodeMirror 6, while react-codemirror2 uses CodeMirror 5. This difference changes how you configure the editor, manage state, and extend functionality. Let's look at the technical details.

πŸ—οΈ Core Engine: Modern Rewrite vs Legacy Stable

@uiw/react-codemirror is built on CodeMirror 6.

  • CodeMirror 6 is a complete rewrite from the ground up.
  • It uses a modular architecture where every feature is an extension.
  • Better support for modern JavaScript and TypeScript.
// @uiw/react-codemirror: CM6 based
import CodeMirror from '@uiw/react-codemirror';
import { javascript } from '@codemirror/lang-javascript';

function Editor() {
  return (
    <CodeMirror
      value="console.log('hello')"
      height="200px"
      extensions={[javascript()]}
    />
  );
}

react-codemirror2 is built on CodeMirror 5.

  • CodeMirror 5 is a monolithic library.
  • Features are often added via global options or external modes.
  • Widely used in older projects but no longer receiving feature updates.
// react-codemirror2: CM5 based
import { UnControlled as CodeMirror } from 'react-codemirror2';
import 'codemirror/mode/javascript/javascript';

function Editor() {
  return (
    <CodeMirror
      value="console.log('hello')"
      options={{
        mode: 'javascript',
        lineNumbers: true
      }}
    />
  );
}

βš™οΈ Configuration: Extensions Array vs Options Object

@uiw/react-codemirror uses an extensions array.

  • You pass an array of extension functions to enable features.
  • This allows for better tree-shaking since you only import what you use.
  • State management is handled internally via the CM6 state field system.
// @uiw/react-codemirror: Extensions
import { lineNumbers } from '@codemirror/view';
import { EditorView } from '@codemirror/view';

<CodeMirror
  extensions={[
    lineNumbers(),
    EditorView.lineWrapping
  ]}
/>

react-codemirror2 uses a configuration object.

  • You pass a single options object with key-value pairs.
  • Enabling features often requires importing mode files globally.
  • Less flexible for customizing specific behaviors without direct instance access.
// react-codemirror2: Options Object
<CodeMirror
  options={{
    lineNumbers: true,
    lineWrapping: true,
    mode: 'javascript'
  }}
/>

🎨 Theming: CSS Variables vs Global Styles

@uiw/react-codemirror supports CM6 theming extensions.

  • Themes are imported as JavaScript extensions.
  • You can mix and match theme parts easily.
  • Styles are scoped and managed via the editor view.
// @uiw/react-codemirror: Theme Extension
import { vscodeDark } from '@uiw/codemirror-theme-vscode';

<CodeMirror
  theme={vscodeDark}
  extensions={[]}
/>

react-codemirror2 relies on CSS classes.

  • You import CSS files for themes manually.
  • You apply a class name to the wrapper or editor container.
  • Global CSS can sometimes leak or conflict with other styles.
// react-codemirror2: CSS Import
import 'codemirror/theme/material.css';

<CodeMirror
  className="material-theme"
  options={{ theme: 'material' }}
/>

πŸ“‘ Event Handling: State Transactions vs Instance Events

@uiw/react-codemirror uses React props for events.

  • Events like onChange return the new value and view state.
  • It aligns with React's controlled component model.
  • Access to the underlying editor view is available via refs if needed.
// @uiw/react-codemirror: React Props
<CodeMirror
  value={code}
  onChange={(value, viewUpdate) => {
    console.log('Value changed:', value);
  }}
/>

react-codemirror2 uses callback props mapped to CM5 events.

  • Events like onBeforeChange or onChange are available.
  • You can access the editor instance directly in some callbacks.
  • Handling complex state updates may require more manual work.
// react-codemirror2: Callback Props
<CodeMirror
  value={code}
  onBeforeChange={(editor, data, value) => {
    console.log('Before change:', value);
  }}
/>

πŸ”Œ Ecosystem: Modular Packages vs Global Modes

@uiw/react-codemirror leverages the CM6 package ecosystem.

  • Language support comes from packages like @codemirror/lang-javascript.
  • Addons are installed as separate npm packages.
  • Easier to manage dependencies and versions.
// @uiw/react-codemirror: Modular Lang
import { python } from '@codemirror/lang-python';

<CodeMirror extensions={[python()]} />

react-codemirror2 uses CM5 mode scripts.

  • Language support often requires importing mode files from codemirror.
  • Some modes are loaded globally on the CodeMirror object.
  • Can lead to larger bundle sizes if many modes are imported.
// react-codemirror2: Global Mode
import 'codemirror/mode/python/python';

<CodeMirror options={{ mode: 'python' }} />

πŸ› οΈ Maintenance: Active Development vs Legacy Support

@uiw/react-codemirror is actively maintained.

  • Receives updates alongside CodeMirror 6 releases.
  • Compatible with modern React versions (16.8+ and 18+).
  • Recommended for all new development work.
// @uiw/react-codemirror: Future Proof
// Continuously updated to support new CM6 features

react-codemirror2 is in maintenance mode.

  • CodeMirror 5 is no longer adding new features.
  • Security fixes may still occur but feature work has stopped.
  • Risk of technical debt if used for new long-term projects.
// react-codemirror2: Legacy Support
// Suitable for keeping existing apps running

🀝 Similarities: Shared Ground Between Both Wrappers

While the underlying engines differ, both packages aim to solve the same integration problems in React. Here are key overlaps:

1. βš›οΈ React Component Interface

  • Both expose a React component you can drop into JSX.
  • Support standard props like value, height, and className.
// Both: Basic Usage
<CodeMirror value={code} height="100%" />

2. πŸ“ Controlled and Uncontrolled Modes

  • Both allow you to manage state externally or internally.
  • You can choose how much control React has over the editor value.
// @uiw: Controlled
<CodeMirror value={code} onChange={setCode} />

// react-codemirror2: UnControlled component
import { UnControlled as CodeMirror } from 'react-codemirror2';
<CodeMirror value={code} />

3. 🌐 Language Support

  • Both support syntax highlighting for dozens of languages.
  • Implementation differs (extensions vs modes), but outcome is similar.
// Both: Highlighting Code
// CM6: extensions={[javascript()]}
// CM5: options={{ mode: 'javascript' }}

4. βœ… Line Numbers and Basics

  • Line numbers, gutters, and basic editing features are standard.
  • Enabled by default or with simple configuration in both.
// Both: Line Numbers
// CM6: lineNumbers() extension
// CM5: lineNumbers: true option

5. πŸ‘₯ Community Resources

  • Both have documentation and examples available online.
  • Large user bases mean issues are often discussed in forums.
// Both: Community Support
// Extensive docs and StackOverflow discussions available

πŸ“Š Summary: Key Similarities

FeatureShared by Both Packages
Interfaceβš›οΈ React Component
State MgmtπŸ“ Controlled/Uncontrolled
Highlighting🌐 Multi-language Support
Basic Featuresβœ… Line Numbers, Gutters
EcosystemπŸ‘₯ Community Docs & Examples

πŸ†š Summary: Key Differences

Feature@uiw/react-codemirrorreact-codemirror2
EngineπŸ—οΈ CodeMirror 6 (Modern)πŸ—οΈ CodeMirror 5 (Legacy)
Configβš™οΈ Extensions Arrayβš™οΈ Options Object
Theming🎨 JS Extensions🎨 CSS Classes
BundlingπŸ”Œ Modular Tree-shakingπŸ”Œ Global Mode Imports
StatusπŸ› οΈ Active DevelopmentπŸ› οΈ Maintenance Mode
Recommendationβœ… New Projects⚠️ Legacy Maintenance

πŸ’‘ The Big Picture

@uiw/react-codemirror is the modern choice πŸš€ β€” built for CodeMirror 6 with a modular design that fits well into contemporary React workflows. It is the right pick for new applications where performance, accessibility, and long-term support matter.

react-codemirror2 is the legacy option πŸ•°οΈ β€” stable and familiar for teams already invested in CodeMirror 5. It works well for keeping existing tools running but introduces technical debt if used for new greenfield projects.

Final Thought: The underlying editor engine drives the decision. CodeMirror 6 is the future of the library, so @uiw/react-codemirror is the strategic choice for most developers today.

How to Choose: @uiw/react-codemirror vs react-codemirror2

  • @uiw/react-codemirror:

    Choose @uiw/react-codemirror for new projects or when you need access to the modern CodeMirror 6 extension system. It offers better tree-shaking, improved accessibility, and active maintenance. This is the standard choice for teams building long-term solutions that require custom editor behaviors and modern React patterns.

  • react-codemirror2:

    Choose react-codemirror2 only if you are maintaining a legacy application that already relies on CodeMirror 5 APIs or specific plugins that have not been ported to CodeMirror 6. It provides a stable interface for existing CM5 workflows but lacks the architectural benefits of the newer version.

README for @uiw/react-codemirror


Using my app is also a way to support me:
Zipora: Zip/RAR/7Z Unarchiver Scap: Screenshot & Markup Edit Screen Test Deskmark Keyzer Vidwall Hub VidCrop Vidwall Mousio Hint Mousio Musicer Audioer FileSentinel FocusCursor Videoer KeyClicker DayBar Iconed Menuist Quick RSS Quick RSS Web Serve Copybook Generator DevTutor for SwiftUI RegexMate Time Passage Iconize Folder Textsound Saver Create Custom Symbols DevHub Resume Revise Palette Genius Symbol Scribe


react-codemirror logo

react-codemirror

Buy me a coffee Follow On X NPM Downloads Build & Deploy Open in unpkg npm version Coverage Status Open in Gitpod

CodeMirror component for React. Demo Preview: @uiwjs.github.io/react-codemirror

Features:

πŸš€ Quickly and easily configure the API.
🌱 Versions after @uiw/react-codemirror@v4 use codemirror 6. #88.
βš›οΈ Support the features of React Hook(requires React 16.8+).
πŸ“š Use Typescript to write, better code hints.
🌐 The bundled version supports use directly in the browser #267.
🌎 There are better sample previews.
🎨 Support theme customization, provide theme editor.
πŸ§‘β€πŸ’» SwiftUI wrapper for CodeMirror 6.

Install

Not dependent on uiw.

npm install @uiw/react-codemirror --save

All Packages

NameNPM Version
@uiw/react-codemirrornpm version NPM Downloads
react-codemirror-mergenpm version NPM Downloads
@uiw/codemirror-extensions-basic-setupnpm version NPM Downloads
@uiw/codemirror-extensions-colornpm version NPM Downloads
@uiw/codemirror-extensions-classnamenpm version NPM Downloads
@uiw/codemirror-extensions-eventsnpm version NPM Downloads
@uiw/codemirror-extensions-hyper-linknpm version NPM Downloads
@uiw/codemirror-extensions-langsnpm version NPM Downloads
@uiw/codemirror-extensions-line-numbers-relativenpm version NPM Downloads
@uiw/codemirror-extensions-mentionsnpm version NPM Downloads
@uiw/codemirror-extensions-zebra-stripesnpm version NPM Downloads
@uiw/codemirror-themesnpm version NPM Downloads
NameNPM Version
@uiw/codemirror-themes-allnpm version NPM Downloads
@uiw/codemirror-theme-abcdefnpm version NPM Downloads
@uiw/codemirror-theme-abyssnpm version NPM Downloads
@uiw/codemirror-theme-androidstudionpm version NPM Downloads
@uiw/codemirror-theme-andromedanpm version NPM Downloads
@uiw/codemirror-theme-atomonenpm version NPM Downloads
@uiw/codemirror-theme-auranpm version NPM Downloads
@uiw/codemirror-theme-basicnpm version NPM Downloads
@uiw/codemirror-theme-bbeditnpm version NPM Downloads
@uiw/codemirror-theme-bespinnpm version NPM Downloads
@uiw/codemirror-theme-consolenpm version NPM Downloads
@uiw/codemirror-theme-copilotnpm version NPM Downloads
@uiw/codemirror-theme-duotonenpm version NPM Downloads
@uiw/codemirror-theme-draculanpm version NPM Downloads
@uiw/codemirror-theme-darculanpm version NPM Downloads
@uiw/codemirror-theme-eclipsenpm version NPM Downloads
@uiw/codemirror-theme-githubnpm version NPM Downloads
@uiw/codemirror-theme-gruvbox-darknpm version NPM Downloads
@uiw/codemirror-theme-kimbienpm version NPM Downloads
@uiw/codemirror-theme-kimbienpm version NPM Downloads
@uiw/codemirror-theme-materialnpm version NPM Downloads
@uiw/codemirror-theme-monokainpm version NPM Downloads
@uiw/codemirror-theme-monokai-dimmednpm version NPM Downloads
@uiw/codemirror-theme-noctis-lilacnpm version NPM Downloads
@uiw/codemirror-theme-nordnpm version NPM Downloads
@uiw/codemirror-theme-okaidianpm version NPM Downloads
@uiw/codemirror-theme-quietlightnpm version NPM Downloads
@uiw/codemirror-theme-rednpm version NPM Downloads
@uiw/codemirror-theme-solarizednpm version NPM Downloads
@uiw/codemirror-theme-sublimenpm version NPM Downloads
@uiw/codemirror-theme-tokyo-nightnpm version NPM Downloads
@uiw/codemirror-theme-tokyo-night-stormnpm version NPM Downloads
@uiw/codemirror-theme-tokyo-night-daynpm version NPM Downloads
@uiw/codemirror-theme-vscodenpm version NPM Downloads
@uiw/codemirror-theme-whitenpm version NPM Downloads
@uiw/codemirror-theme-tomorrow-night-bluenpm version NPM Downloads
@uiw/codemirror-theme-xcodenpm version NPM Downloads

Usage

Open in CodeSandbox

import React from 'react';
import CodeMirror from '@uiw/react-codemirror';
import { javascript } from '@codemirror/lang-javascript';

function App() {
  const [value, setValue] = React.useState("console.log('hello world!');");
  const onChange = React.useCallback((val, viewUpdate) => {
    console.log('val:', val);
    setValue(val);
  }, []);
  return <CodeMirror value={value} height="200px" extensions={[javascript({ jsx: true })]} onChange={onChange} />;
}
export default App;

Support Language

Open in CodeSandbox

import CodeMirror from '@uiw/react-codemirror';
import { StreamLanguage } from '@codemirror/language';
import { go } from '@codemirror/legacy-modes/mode/go';

const goLang = `package main
import "fmt"

func main() {
  fmt.Println("Hello, δΈ–η•Œ")
}`;

export default function App() {
  return <CodeMirror value={goLang} height="200px" extensions={[StreamLanguage.define(go)]} />;
}

Markdown Example

Markdown language code is automatically highlighted.

Open in CodeSandbox

import CodeMirror from '@uiw/react-codemirror';
import { markdown, markdownLanguage } from '@codemirror/lang-markdown';
import { languages } from '@codemirror/language-data';

const code = `## Title

\`\`\`jsx
function Demo() {
  return <div>demo</div>
}
\`\`\`

\`\`\`bash
# Not dependent on uiw.
npm install @codemirror/lang-markdown --save
npm install @codemirror/language-data --save
\`\`\`

[weisit ulr](https://uiwjs.github.io/react-codemirror/)

\`\`\`go
package main
import "fmt"
func main() {
  fmt.Println("Hello, δΈ–η•Œ")
}
\`\`\`
`;

export default function App() {
  return <CodeMirror value={code} extensions={[markdown({ base: markdownLanguage, codeLanguages: languages })]} />;
}

Codemirror Merge

A component that highlights the changes between two versions of a file in a side-by-side view, highlighting added, modified, or deleted lines of code.

npm install react-codemirror-merge  --save
import CodeMirrorMerge from 'react-codemirror-merge';
import { EditorView } from 'codemirror';
import { EditorState } from '@codemirror/state';

const Original = CodeMirrorMerge.Original;
const Modified = CodeMirrorMerge.Modified;
let doc = `one
two
three
four
five`;

export const Example = () => {
  return (
    <CodeMirrorMerge>
      <Original value={doc} />
      <Modified
        value={doc.replace(/t/g, 'T') + 'Six'}
        extensions={[EditorView.editable.of(false), EditorState.readOnly.of(true)]}
      />
    </CodeMirrorMerge>
  );
};

Support Hook

Open in CodeSandbox

import { useEffect, useMemo, useRef } from 'react';
import { useCodeMirror } from '@uiw/react-codemirror';
import { javascript } from '@codemirror/lang-javascript';

const code = "console.log('hello world!');\n\n\n";
// Define the extensions outside the component for the best performance.
// If you need dynamic extensions, use React.useMemo to minimize reference changes
// which cause costly re-renders.
const extensions = [javascript()];

export default function App() {
  const editor = useRef();
  const { setContainer } = useCodeMirror({
    container: editor.current,
    extensions,
    value: code,
  });

  useEffect(() => {
    if (editor.current) {
      setContainer(editor.current);
    }
  }, [editor.current]);

  return <div ref={editor} />;
}

Using Theme

We have created a theme editor where you can define your own theme. We have also defined some themes ourselves, which can be installed and used directly. Below is a usage example:

import CodeMirror from '@uiw/react-codemirror';
import { javascript } from '@codemirror/lang-javascript';
import { okaidia } from '@uiw/codemirror-theme-okaidia';

const extensions = [javascript({ jsx: true })];

export default function App() {
  return <CodeMirror value="console.log('hello world!');" height="200px" theme={okaidia} extensions={extensions} />;
}

Using custom theme

import CodeMirror from '@uiw/react-codemirror';
import { createTheme } from '@uiw/codemirror-themes';
import { javascript } from '@codemirror/lang-javascript';
import { tags as t } from '@lezer/highlight';

const myTheme = createTheme({
  theme: 'light',
  settings: {
    background: '#ffffff',
    backgroundImage: '',
    foreground: '#75baff',
    caret: '#5d00ff',
    selection: '#036dd626',
    selectionMatch: '#036dd626',
    lineHighlight: '#8a91991a',
    gutterBackground: '#fff',
    gutterForeground: '#8a919966',
  },
  styles: [
    { tag: t.comment, color: '#787b8099' },
    { tag: t.variableName, color: '#0080ff' },
    { tag: [t.string, t.special(t.brace)], color: '#5c6166' },
    { tag: t.number, color: '#5c6166' },
    { tag: t.bool, color: '#5c6166' },
    { tag: t.null, color: '#5c6166' },
    { tag: t.keyword, color: '#5c6166' },
    { tag: t.operator, color: '#5c6166' },
    { tag: t.className, color: '#5c6166' },
    { tag: t.definition(t.typeName), color: '#5c6166' },
    { tag: t.typeName, color: '#5c6166' },
    { tag: t.angleBracket, color: '#5c6166' },
    { tag: t.tagName, color: '#5c6166' },
    { tag: t.attributeName, color: '#5c6166' },
  ],
});
const extensions = [javascript({ jsx: true })];

export default function App() {
  const onChange = React.useCallback((value, viewUpdate) => {
    console.log('value:', value);
  }, []);
  return (
    <CodeMirror
      value="console.log('hello world!');"
      height="200px"
      theme={myTheme}
      extensions={extensions}
      onChange={onChange}
    />
  );
}

Use initialState to restore state from JSON-serialized representation

CodeMirror allows to serialize editor state to JSON representation with toJSON function for persistency or other needs. This JSON representation can be later used to recreate ReactCodeMirror component with the same internal state.

For example, this is how undo history can be saved in the local storage, so that it remains after the page reloads

import CodeMirror from '@uiw/react-codemirror';
import { historyField } from '@codemirror/commands';

// When custom fields should be serialized, you can pass them in as an object mapping property names to fields.
// See [toJSON](https://codemirror.net/docs/ref/#state.EditorState.toJSON) documentation for more details
const stateFields = { history: historyField };

export function EditorWithInitialState() {
  const serializedState = localStorage.getItem('myEditorState');
  const value = localStorage.getItem('myValue') || '';

  return (
    <CodeMirror
      value={value}
      initialState={
        serializedState
          ? {
              json: JSON.parse(serializedState || ''),
              fields: stateFields,
            }
          : undefined
      }
      onChange={(value, viewUpdate) => {
        localStorage.setItem('myValue', value);

        const state = viewUpdate.state.toJSON(stateFields);
        localStorage.setItem('myEditorState', JSON.stringify(state));
      }}
    />
  );
}

Props

  • value?: string value of the auto created model in the editor.
  • width?: string width of editor. Defaults to auto.
  • height?: string height of editor. Defaults to auto.
  • theme?: 'light' / 'dark' / Extension Defaults to 'light'.
import React from 'react';
import { EditorState, EditorStateConfig, Extension } from '@codemirror/state';
import { EditorView, ViewUpdate } from '@codemirror/view';
export * from '@codemirror/view';
export * from '@codemirror/basic-setup';
export * from '@codemirror/state';
export declare const ExternalChange: import('@codemirror/state').AnnotationType<boolean>;
export interface UseCodeMirror extends ReactCodeMirrorProps {
  container?: HTMLDivElement | null;
}
export declare function useCodeMirror(props: UseCodeMirror): {
  state: EditorState | undefined;
  setState: import('react').Dispatch<import('react').SetStateAction<EditorState | undefined>>;
  view: EditorView | undefined;
  setView: import('react').Dispatch<import('react').SetStateAction<EditorView | undefined>>;
  container: HTMLDivElement | null | undefined;
  setContainer: import('react').Dispatch<import('react').SetStateAction<HTMLDivElement | null | undefined>>;
};
export interface ReactCodeMirrorProps
  extends
    Omit<EditorStateConfig, 'doc' | 'extensions'>,
    Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange' | 'placeholder'> {
  /** value of the auto created model in the editor. */
  value?: string;
  height?: string;
  minHeight?: string;
  maxHeight?: string;
  width?: string;
  minWidth?: string;
  maxWidth?: string;
  /** focus on the editor. */
  autoFocus?: boolean;
  /** Enables a placeholderβ€”a piece of example content to show when the editor is empty. */
  placeholder?: string | HTMLElement;
  /**
   * `light` / `dark` / `Extension` Defaults to `light`.
   * @default light
   */
  theme?: 'light' | 'dark' | Extension;
  /**
   * Whether to optional basicSetup by default
   * @default true
   */
  basicSetup?: boolean | BasicSetupOptions;
  /**
   * This disables editing of the editor content by the user.
   * @default true
   */
  editable?: boolean;
  /**
   * This disables editing of the editor content by the user.
   * @default false
   */
  readOnly?: boolean;
  /**
   * Controls whether pressing the `Tab` key inserts a tab character and indents the text (`true`)
   * or behaves according to the browser's default behavior (`false`).
   * @default true
   */
  indentWithTab?: boolean;
  /** Fired whenever a change occurs to the document. */
  onChange?(value: string, viewUpdate: ViewUpdate): void;
  /** Some data on the statistics editor. */
  onStatistics?(data: Statistics): void;
  /** The first time the editor executes the event. */
  onCreateEditor?(view: EditorView, state: EditorState): void;
  /** Fired whenever any state change occurs within the editor, including non-document changes like lint results. */
  onUpdate?(viewUpdate: ViewUpdate): void;
  /**
   * Extension values can be [provided](https://codemirror.net/6/docs/ref/#state.EditorStateConfig.extensions) when creating a state to attach various kinds of configuration and behavior information.
   * They can either be built-in extension-providing objects,
   * such as [state fields](https://codemirror.net/6/docs/ref/#state.StateField) or [facet providers](https://codemirror.net/6/docs/ref/#state.Facet.of),
   * or objects with an extension in its `extension` property. Extensions can be nested in arrays arbitrarily deepβ€”they will be flattened when processed.
   */
  extensions?: Extension[];
  /**
   * If the view is going to be mounted in a shadow root or document other than the one held by the global variable document (the default), you should pass it here.
   * Originally from the [config of EditorView](https://codemirror.net/6/docs/ref/#view.EditorView.constructor%5Econfig.root)
   */
  root?: ShadowRoot | Document;
  /**
   * Create a state from its JSON representation serialized with [toJSON](https://codemirror.net/docs/ref/#state.EditorState.toJSON) function
   */
  initialState?: {
    json: any;
    fields?: Record<'string', StateField<any>>;
  };
}
export interface ReactCodeMirrorRef {
  editor?: HTMLDivElement | null;
  state?: EditorState;
  view?: EditorView;
}
declare const ReactCodeMirror: React.ForwardRefExoticComponent<
  ReactCodeMirrorProps & React.RefAttributes<ReactCodeMirrorRef>
>;
export default ReactCodeMirror;
export interface BasicSetupOptions {
  lineNumbers?: boolean;
  highlightActiveLineGutter?: boolean;
  highlightSpecialChars?: boolean;
  history?: boolean;
  foldGutter?: boolean;
  drawSelection?: boolean;
  dropCursor?: boolean;
  allowMultipleSelections?: boolean;
  indentOnInput?: boolean;
  syntaxHighlighting?: boolean;
  bracketMatching?: boolean;
  closeBrackets?: boolean;
  autocompletion?: boolean;
  rectangularSelection?: boolean;
  crosshairCursor?: boolean;
  highlightActiveLine?: boolean;
  highlightSelectionMatches?: boolean;
  closeBracketsKeymap?: boolean;
  defaultKeymap?: boolean;
  searchKeymap?: boolean;
  historyKeymap?: boolean;
  foldKeymap?: boolean;
  completionKeymap?: boolean;
  lintKeymap?: boolean;
}
import { EditorSelection, SelectionRange } from '@codemirror/state';
import { ViewUpdate } from '@codemirror/view';
export interface Statistics {
  /** Get the number of lines in the editor. */
  lineCount: number;
  /** total length of the document */
  length: number;
  /** Get the proper [line-break](https://codemirror.net/docs/ref/#state.EditorState^lineSeparator) string for this state. */
  lineBreak: string;
  /** Returns true when the editor is [configured](https://codemirror.net/6/docs/ref/#state.EditorState^readOnly) to be read-only. */
  readOnly: boolean;
  /** The size (in columns) of a tab in the document, determined by the [`tabSize`](https://codemirror.net/6/docs/ref/#state.EditorState^tabSize) facet. */
  tabSize: number;
  /** Cursor Position */
  selection: EditorSelection;
  /** Make sure the selection only has one range. */
  selectionAsSingle: SelectionRange;
  /** Retrieves a list of all current selections. */
  ranges: readonly SelectionRange[];
  /** Get the currently selected code. */
  selectionCode: string;
  /**
   * The length of the given array should be the same as the number of active selections.
   * Replaces the content of the selections with the strings in the array.
   */
  selections: string[];
  /** Return true if any text is selected. */
  selectedText: boolean;
}
export declare const getStatistics: (view: ViewUpdate) => Statistics;

Development

  1. Install dependencies
$ npm install       # Installation dependencies
$ npm run build     # Compile all package
  1. Development @uiw/react-codemirror package:
$ cd core
# listen to the component compile and output the .js file
# listen for compilation output type .d.ts file
$ npm run watch # Monitor the compiled package `@uiw/react-codemirror`
  1. Launch documentation site
npm run start

Related

Contributors

As always, thanks to our amazing contributors!

Made with contributors.

License

Licensed under the MIT License.