@uiw/react-codemirror
CodeMirror component for React.
Last updated 3 years ago by wcjiang .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install @uiw/react-codemirror 
SYNC missed versions from official npm registry.

react-codemirror

Downloads Build & Deploy Open in unpkg npm version

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

Features:

๐Ÿš€ Quickly and easily configure the API.
๐ŸŒฑ Use codemirror 6.
โš›๏ธ Support the features of React Hook(requires React 16.8+).
๐Ÿ“š Use Typescript to write, better code hints.
๐ŸŒŽ There are better sample previews.

Install

# Not dependent on uiw.
npm install @uiw/react-codemirror --save

Usage

Open in CodeSandbox

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

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

Support Hook

Open in CodeSandbox

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

const code = "console.log('hello world!');\n\n\n";

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

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

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

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 Defaults to light.
import React from "react";
import { EditorState, EditorStateConfig, Extension } from "@codemirror/state";
import { EditorView } from "@codemirror/view";
export * from './useCodeMirror';
export * from "@codemirror/view";
export * from "@codemirror/basic-setup";
export * from "@codemirror/state";
export interface ReactCodeMirrorProps extends Omit<EditorStateConfig, 'doc' | 'extensions'>, Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'> {
  /**
   * value of the auto created model in the editor.
   */
  value?: string;
  height?: string;
  minHeight?: string;
  maxHeight?: string;
  width?: string;
  minWidth?: string;
  maxWidth?: string;
  theme?: 'light' | 'dark';
  /**
   * Fired whenever a change occurs to the document.
   */
  onChange?(value: string, 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[];
}
export interface ReactCodeMirrorRef {
  editor?: HTMLDivElement | null;
  state?: EditorState;
  view?: EditorView;
}

Related

License

Licensed under the MIT License.

Current Tags

  • 4.23.5                                ...           latest (a month ago)
  • 3.2.5                                ...           next (3 years ago)
  • 3.2.10                                ...           previous (2 years ago)

206 Versions

  • 4.23.5                                ...           a month ago
  • 4.23.4                                ...           a month ago
  • 4.23.1                                ...           2 months ago
  • 4.23.0                                ...           4 months ago
  • 4.22.2                                ...           5 months ago
  • 4.22.1                                ...           6 months ago
  • 4.22.0                                ...           7 months ago
  • 4.21.25                                ...           8 months ago
  • 4.21.24                                ...           9 months ago
  • 4.21.23                                ...           9 months ago
  • 4.21.22                                ...           9 months ago
  • 4.21.21                                ...           a year ago
  • 4.21.20                                ...           a year ago
  • 4.21.19                                ...           a year ago
  • 4.21.18                                ...           a year ago
  • 4.21.17                                ...           a year ago
  • 4.21.16                                ...           a year ago
  • 4.21.15                                ...           a year ago
  • 4.21.14                                ...           a year ago
  • 4.21.13                                ...           a year ago
  • 4.21.12                                ...           a year ago
  • 4.21.11                                ...           a year ago
  • 4.21.10                                ...           a year ago
  • 4.21.9                                ...           a year ago
  • 4.21.8                                ...           a year ago
  • 4.21.7                                ...           a year ago
  • 4.21.6                                ...           a year ago
  • 4.21.5                                ...           a year ago
  • 4.21.4                                ...           a year ago
  • 4.21.3                                ...           a year ago
  • 4.21.2                                ...           a year ago
  • 4.21.1                                ...           a year ago
  • 4.21.0                                ...           a year ago
  • 4.20.4                                ...           a year ago
  • 4.20.3                                ...           a year ago
  • 4.20.2                                ...           a year ago
  • 4.20.1                                ...           a year ago
  • 4.20.0                                ...           a year ago
  • 3.2.10                                ...           2 years ago
  • 4.19.16                                ...           2 years ago
  • 4.19.15                                ...           2 years ago
  • 4.19.14                                ...           2 years ago
  • 4.19.13                                ...           2 years ago
  • 4.19.12                                ...           2 years ago
  • 4.19.11                                ...           2 years ago
  • 4.19.10                                ...           2 years ago
  • 4.19.9                                ...           2 years ago
  • 4.19.8                                ...           2 years ago
  • 4.19.7                                ...           2 years ago
  • 4.19.6                                ...           2 years ago
  • 4.19.5                                ...           2 years ago
  • 4.19.4                                ...           2 years ago
  • 4.19.3                                ...           2 years ago
  • 4.19.2                                ...           2 years ago
  • 4.19.1                                ...           2 years ago
  • 4.19.0                                ...           2 years ago
  • 4.18.2                                ...           2 years ago
  • 4.18.1                                ...           2 years ago
  • 4.18.0                                ...           2 years ago
  • 4.17.1                                ...           2 years ago
  • 4.17.0                                ...           2 years ago
  • 4.16.0                                ...           2 years ago
  • 4.15.1                                ...           2 years ago
  • 4.15.0                                ...           2 years ago
  • 4.14.3                                ...           2 years ago
  • 4.14.2                                ...           2 years ago
  • 4.14.1                                ...           2 years ago
  • 4.14.0                                ...           2 years ago
  • 4.13.2                                ...           2 years ago
  • 4.13.1                                ...           2 years ago
  • 4.13.0                                ...           2 years ago
  • 4.12.4                                ...           2 years ago
  • 4.12.3                                ...           2 years ago
  • 4.12.2                                ...           2 years ago
  • 3.2.9                                ...           2 years ago
  • 4.12.1                                ...           2 years ago
  • 4.12.0                                ...           2 years ago
  • 4.11.6                                ...           2 years ago
  • 4.11.5                                ...           2 years ago
  • 3.2.8                                ...           2 years ago
  • 4.11.4                                ...           2 years ago
  • 4.11.3                                ...           2 years ago
  • 4.11.2                                ...           2 years ago
  • 4.11.1                                ...           2 years ago
  • 4.11.0                                ...           2 years ago
  • 4.10.4                                ...           2 years ago
  • 4.10.3                                ...           2 years ago
  • 4.10.2                                ...           2 years ago
  • 4.10.1                                ...           2 years ago
  • 4.10.0                                ...           2 years ago
  • 4.9.6                                ...           2 years ago
  • 4.9.5                                ...           2 years ago
  • 4.9.4                                ...           2 years ago
  • 4.9.3                                ...           2 years ago
  • 4.9.2                                ...           2 years ago
  • 4.9.1                                ...           2 years ago
  • 4.9.0                                ...           2 years ago
  • 4.8.1                                ...           2 years ago
  • 4.8.0                                ...           2 years ago
  • 4.7.0                                ...           3 years ago
  • 4.6.0                                ...           3 years ago
  • 4.5.3                                ...           3 years ago
  • 4.5.2                                ...           3 years ago
  • 4.5.1                                ...           3 years ago
  • 4.5.0                                ...           3 years ago
  • 4.4.3                                ...           3 years ago
  • 4.4.2                                ...           3 years ago
  • 4.4.1                                ...           3 years ago
  • 4.4.0                                ...           3 years ago
  • 4.3.3                                ...           3 years ago
  • 4.3.2                                ...           3 years ago
  • 4.3.1                                ...           3 years ago
  • 4.3.0                                ...           3 years ago
  • 4.2.4                                ...           3 years ago
  • 4.2.3                                ...           3 years ago
  • 4.2.2                                ...           3 years ago
  • 4.2.1                                ...           3 years ago
  • 4.2.0                                ...           3 years ago
  • 4.1.0                                ...           3 years ago
  • 4.0.8                                ...           3 years ago
  • 4.0.7                                ...           3 years ago
  • 4.0.6                                ...           3 years ago
  • 3.2.7                                ...           3 years ago
  • 3.2.6                                ...           3 years ago
  • 3.2.5                                ...           3 years ago
  • 3.2.4                                ...           3 years ago
  • 3.2.3                                ...           3 years ago
  • 3.2.2                                ...           3 years ago
  • 4.0.5                                ...           3 years ago
  • 4.0.4                                ...           3 years ago
  • 4.0.3                                ...           3 years ago
  • 4.0.2                                ...           3 years ago
  • 4.0.1                                ...           3 years ago
  • 4.0.0                                ...           3 years ago
  • 4.0.0-rc.14                                ...           3 years ago
  • 4.0.0-rc.13                                ...           3 years ago
  • 4.0.0-rc.12                                ...           3 years ago
  • 4.0.0-rc.11                                ...           3 years ago
  • 4.0.0-rc.10                                ...           3 years ago
  • 4.0.0-rc.9                                ...           3 years ago
  • 4.0.0-rc.8                                ...           3 years ago
  • 4.0.0-rc.7                                ...           3 years ago
  • 4.0.0-rc.6                                ...           3 years ago
  • 4.0.0-rc.5                                ...           3 years ago
  • 4.0.0-rc.4                                ...           3 years ago
  • 4.0.0-rc.3                                ...           3 years ago
  • 4.0.0-rc.2                                ...           3 years ago
  • 4.0.0-rc.1                                ...           3 years ago
  • 4.0.0-rc.0                                ...           3 years ago
  • 3.2.1                                ...           3 years ago
  • 3.1.0                                ...           3 years ago
  • 3.0.15                                ...           3 years ago
  • 3.0.14                                ...           3 years ago
  • 3.0.13                                ...           3 years ago
  • 3.0.12                                ...           3 years ago
  • 3.0.11                                ...           3 years ago
  • 3.0.10                                ...           3 years ago
  • 3.0.9                                ...           3 years ago
  • 3.0.8                                ...           4 years ago
  • 3.0.7                                ...           4 years ago
  • 3.0.6                                ...           4 years ago
  • 3.0.5                                ...           4 years ago
  • 3.0.4                                ...           4 years ago
  • 3.0.3                                ...           4 years ago
  • 3.0.2                                ...           4 years ago
  • 3.0.1                                ...           4 years ago
  • 3.0.0                                ...           4 years ago
  • 2.3.5                                ...           4 years ago
  • 2.3.4                                ...           4 years ago
  • 2.3.3                                ...           4 years ago
  • 2.3.2                                ...           4 years ago
  • 2.3.1                                ...           4 years ago
  • 2.3.0                                ...           4 years ago
  • 2.2.1                                ...           5 years ago
  • 2.2.0                                ...           5 years ago
  • 2.1.0                                ...           5 years ago
  • 2.0.1                                ...           5 years ago
  • 2.0.0                                ...           5 years ago
  • 1.1.0                                ...           5 years ago
  • 1.0.28                                ...           5 years ago
  • 1.0.27                                ...           5 years ago
  • 1.0.26                                ...           5 years ago
  • 1.0.25                                ...           5 years ago
  • 1.0.24                                ...           5 years ago
  • 1.0.23                                ...           5 years ago
  • 1.0.22                                ...           5 years ago
  • 1.0.21                                ...           5 years ago
  • 1.0.19                                ...           6 years ago
  • 1.0.18                                ...           6 years ago
  • 1.0.17                                ...           6 years ago
  • 1.0.16                                ...           6 years ago
  • 1.0.15                                ...           6 years ago
  • 1.0.14                                ...           6 years ago
  • 1.0.13                                ...           6 years ago
  • 1.0.12                                ...           6 years ago
  • 1.0.11                                ...           6 years ago
  • 1.0.9                                ...           6 years ago
  • 1.0.8                                ...           6 years ago
  • 1.0.7                                ...           6 years ago
  • 1.0.6                                ...           6 years ago
  • 1.0.5                                ...           6 years ago
  • 1.0.4                                ...           6 years ago
  • 1.0.3                                ...           6 years ago
  • 1.0.2                                ...           6 years ago
  • 1.0.1                                ...           6 years ago
  • 1.0.0                                ...           6 years ago
Maintainers (1)
Downloads
Total 1
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE