React-Ace Editor Component

14.0.1 · active · verified Sun Apr 19

React-Ace provides a set of React components that wrap the Ace Editor, a high-performance code editor, allowing developers to easily embed sophisticated code editing capabilities into their React applications. The current stable version is 14.0.1, which includes support for React 19. The project demonstrates an active release cadence with frequent minor and patch updates, alongside periodic major version bumps to incorporate new features, bug fixes, and dependency upgrades, often aligning with updates to `ace-builds` itself. Key differentiators include its robust API for controlling editor behavior, support for various modes, themes, and extensions through the `ace-builds` package, and dedicated components for split view and diff editing, offering a comprehensive solution for interactive code snippets, IDE-like features, or rich text editing with syntax highlighting.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates rendering a basic AceEditor component with JavaScript mode, GitHub theme, and essential extensions like language tools for autocompletion. It logs changes to the console and includes basic editor options for enhanced usability.

import React from "react";
import { createRoot } from "react-dom/client";
import AceEditor from "react-ace";

import "ace-builds/src-noconflict/mode-javascript";
import "ace-builds/src-noconflict/theme-github";
import "ace-builds/src-noconflict/ext-language_tools";

function MyAceEditor() {
  const onChange = (newValue) => {
    console.log("Editor content changed:", newValue);
  };

  return (
    <AceEditor
      mode="javascript"
      theme="github"
      onChange={onChange}
      name="code-editor-instance"
      editorProps={{ $blockScrolling: true }}
      setOptions={{
        enableBasicAutocompletion: true,
        enableLiveAutocompletion: true,
        enableSnippets: true,
        showLineNumbers: true,
        tabSize: 2,
      }}
      style={{
        width: '100%',
        height: '300px'
      }}
      placeholder="Start coding here..."
    />
  );
}

const container = document.getElementById('example');
if (container) {
  const root = createRoot(container);
  root.render(<MyAceEditor />);
} else {
  console.error("Root element 'example' not found.");
}

view raw JSON →