# @codingame/monaco-editor-react 中文文档

规范地址：https://npmcn.com/package/%40codingame/monaco-editor-react/

版本：34\.0\.0
npm 元数据更新时间：2026-11-06T15:59:15.471Z
中文译文更新时间：2026-11-10T08:54:57.694Z
软件包许可：未声明

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40codingame/monaco-editor-react
原文对照：https://npmcn.com/package/%40codingame/monaco-editor-react/?lang=original
项目主页：https://github.com/CodinGame/monaco-editor-react#readme
源码仓库：https://github.com/CodinGame/monaco-editor-react

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：49.4 kB，17 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- 运行依赖：6 个
- peer 依赖：react \>=16\.0\.0
- 首次发布：2021-11-09T17:18:05.065Z
- 最新版本发布：2026-11-06T15:59:15.072Z
- 近 30 天下载量：2883（2026-10-10 至 2026-11-08，npm 官方下载统计）
- 已发布版本数：88（近 12 个月 20 个）

## 中文简介

摩纳哥编辑器反应组件

## 安装

```sh
npm install @codingame/monaco-editor-react
```

也可以使用：`pnpm add @codingame/monaco-editor-react`、`yarn add @codingame/monaco-editor-react`、`bun add @codingame/monaco-editor-react`

## README

# @codingame/monaco-editor-react)- [![monthly downloads](https://img.shields.io/npm/dm/@codingame/monaco-editor-react)](https://www.npmjs.com/package/@codingame/monaco-editor-react) [![npm version](https://img.shields.io/npm/v/@codingame/monaco-editor-react.svg?style=flat)](https://www.npmjs.com/package/@codingame/monaco-editor-react) [![PRs welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/codingame/monaco-editor-react/pulls)

## 概要

此库使用 [https://github.com/ CodinGame/monaco-editor-wrapper 互联网档案馆的存檔,存档日期2013-12-02](https://github.com/CodinGame/monaco-editor-wrapper)

请参见本文件

### 安装

```bash
npm install @codingame/monaco-editor-react 
```

### 使用量

#### 简单使用

以下是简单整合 `monaco` 带编辑器 `React` 项目. 你只需要进口和制造 `Editor` 组件 :

```typescript
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);
```

#### 模型管理

当您制作摩纳哥编辑器组件时,模式管理有两种模式:

-   如果该型号已经存在,则该型号将在尾端被再利用并作处置
-   如果模型不存在,它将会被创建和处理

这样,编辑器是插件和游戏,用于简单的使用大小写,但它允许您先创建模型,在编辑器中使用模型,并在您不再需要时处理模型

### 与 [摩纳哥反应](https://github.com/suren-atoyan/monaco-react)

-   此库输出一些动态 `import` 并依靠网络包装来处理它们
-   模型管理是不同的,要么用手管理模型,要么让编辑者创建并摧毁模型
-   没有 `onValidate`:可以直接用monaco.editor.on完成. 变化马克斯
-   没有主题道具: 主题可以使用 `monaco.editor.setTheme`
-   要获取编辑器实例, 请使用 `ref` 改为 `handleEditorDidMount`
-   没有 `useMonaco`,您只需使用导出 `monaco`数字 : `import { monaco }, Editor from "@codingame/monaco-editor-react";`

## 常见问题

### @codingame/monaco-editor-react 是什么？

摩纳哥编辑器反应组件

### 如何安装 @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 和提交记录判断。

