@codingame/monaco-editor-react

中文文档
34.0.0发布于 2026/11/06TypeScriptES Module构建来源已验证近 30 天下载 2883

Monaco Editor React component

原始使用文档
文档目录4 节
  1. Synopsis
  2. Installation
  3. Usage
  4. Differences with monaco-react

@codingame/monaco-editor-react · monthly downloads npm version PRs welcome

Synopsis

This library uses https://github.com/CodinGame/monaco-editor-wrapper

Please refer to this documentation

Installation

npm install @codingame/monaco-editor-react 

Usage

Simple usage

Here is an example of a simple integration of monaco editor with a React project. You just need to import and render the Editor component:

import React from "react";
import ReactDOM from "react-dom";

import Editor from "@codingame/monaco-editor-react";

function App() {
  const [value, setValue] = useState('// some comment');
  return (
   <Editor
     height="auto"
     programmingLanguage="javascript"
     value={value}
     onChange={setValue}
   />
  );
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);

Models management

When you render the MonacoEditor component, there is 2 modes for the model management:

  • if the model already exists, it will be reused and not disposed at the end
  • if the model doesn't exist, it will be created and disposed at the end

This way, the editor is plug-and-play for simple use cases but it allows you to create your models before, use them in the editor and dispose them when you don't need them anymore

Differences with monaco-react

  • This library outputs some dynamic import and rely on webpack to handle them
  • The model management is different, either you manage your models by hands or let the editor create and destroy them
  • no onValidate: can be done directly with monaco.editor.onDidChangeMarkers
  • no theme prop: the theme can be changed using monaco.editor.setTheme
  • To get the editor instance, use ref instead of handleEditorDidMount
  • There is no useMonaco, you can just use the exported monaco: import { monaco }, Editor from "@codingame/monaco-editor-react";

版本与发布记录

@codingame/monaco-editor-react 共发布 88 个版本,首次发布于 2021/11/10;过去 12 个月发布了 20 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
34.0.0latest2026/11/063 天前
33.0.02026/10/2021 天前
32.0.12026/09/301 个月前
32.0.02026/09/221 个月前
31.0.02026/08/182 个月前
30.0.02026/07/104 个月前

其他发布通道:next → 5.0.0-update-monaco.3。

关于 @codingame/monaco-editor-react 的常见问题

@codingame/monaco-editor-react 是什么?

Monaco Editor React component

如何安装 @codingame/monaco-editor-react?

在项目目录运行 npm install @codingame/monaco-editor-react,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=16.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@codingame/monaco-editor-react 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@codingame/monaco-editor-react 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@codingame/monaco-editor-react 可以商用吗?

@codingame/monaco-editor-react 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@codingame/monaco-editor-react 的下载量有多少?

根据 npm 官方下载统计,@codingame/monaco-editor-react 在 2026/10/10 – 2026/11/08 这 30 天内被下载 2,883 次,日均约 96 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@codingame/monaco-editor-react 还在维护吗?

最新版本 34.0.0 发布于 2026/11/06(3 天前);至今共发布 88 个版本,其中过去 12 个月发布了 20 个;首次发布于 2021/11/10。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。