@fluentui/react-monaco-editor

中文文档
1.8.14发布于 2026/10/29MITTypeScriptESM + CJS近 30 天下载 2951

Live React example editing using monaco

原始使用文档
文档目录11 节
  1. Features
  2. Live updating as user types
  3. Typings support
  4. Delay loading
  5. Read-only rendering in unsupported browsers
  6. Setup
  7. API options
  8. EditorWrapper : Full editor + example rendering
  9. TsxEditor : Editor + transpile/eval example
  10. Editor : Editor only
  11. Advanced usage

@fluentui/react-monaco-editor

Monaco-based TypeScript+React live code editor with full typing support. It was primarily written for component examples on the Fluent UI React website (formerly Office UI Fabric React), but it can be configured to work with other libraries too.

WARNING: The editor component's API is still highly unstable, so it should not be used outside the Fluent UI React repo yet.

Features

Live updating as user types

As the user edits TypeScript+React example code, it will be transpiled and rendered onto the page.

Typings support

By default, the editor will load types for React and Fluent UI React. It can also be configured to load types for any package.

Delay loading

Monaco's code is very large and should be loaded after main page content is ready. When consumed with Webpack, this package takes care of delay loading Monaco.

Read-only rendering in unsupported browsers

If the user's browser can't support the editor (mainly IE 11 and some mobile browsers), the code will be rendered read-only.

Setup

Follow the Webpack and runtime configuration instructions from the @fluentui/monaco-editor readme. Note that the helpers used are re-exported from this package for convenience:

  • addMonacoWebpackConfig: import from @fluentui/react-monaco-editor/scripts/addMonacoWebpackConfig
  • configureEnvironment and IMonacoConfig: import from @fluentui/react-monaco-editor

Then choose one of the API options below for rendering the editor.

API options

This package offers multiple options for rendering a Monaco editor and/or a TypeScript+React example.

Note that these are still subject to change until a major release.

EditorWrapper: Full editor + example rendering

EditorWrapper renders a Monaco editor, a container where the example is rendered, and a message bar with errors (when applicable). As the user types, EditorWrapper transpiles the updated example component code, evals it, and re-renders the example component.

If the user's browser can't support the editor, the code will be rendered read-only.

TODO: add usage example

TsxEditor: Editor + transpile/eval example

TsxEditor is like EditorWrapper, but without the example container, error bar, or read-only fallback. Instead of rendering the example itself, it takes in an onTransformFinished callback to pass the example component up to the parent for rendering.

Notes for this option:

  • You should delay load the TsxEditor component to prevent Monaco from being pulled into your main bundle.
    • TsxEditor isn't included in @fluentui/react-monaco-editor/lib/index due to importing Monaco. It should be imported from @fluentui/react-monaco-editor/lib/TsxEditor instead.
  • When rendering the example component, be sure to wrap it in an error boundary; otherwise runtime errors in the example will crash the page. (One option is using EditorErrorBoundary, which also handles displaying transform errors.)

TODO: add usage example

Editor: Editor only

Editor renders only Monaco. It works with any language and doesn't do any extra TypeScript setup.

Note that if you choose this option, you should delay load the Editor component to prevent Monaco from being pulled into your main bundle. (Editor isn't included in @fluentui/react-monaco-editor/lib/index due to importing Monaco. It should be imported from @fluentui/react-monaco-editor/lib/Editor instead.)

TODO: add usage example

Advanced usage

TODO: add example of customizing typings and globals, and info about example code requirements

版本与发布记录

@fluentui/react-monaco-editor 共发布 725 个版本,首次发布于 2020/10/23;过去 12 个月发布了 12 个版本。

版本发布日期距今
1.8.14latest2026/10/2917 天前
1.8.132026/10/2620 天前
1.8.122026/10/011 个月前
1.8.112026/07/014 个月前
1.8.102026/05/265 个月前
1.8.92026/05/195 个月前

其他发布通道:beta → 1.0.0-beta.52。

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

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

Live React example editing using monaco

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

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

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

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

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

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

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

@fluentui/react-monaco-editor 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

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

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

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

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