Gathering detailed insights and metrics for react-monaco-editor
Gathering detailed insights and metrics for react-monaco-editor
Gathering detailed insights and metrics for react-monaco-editor
Gathering detailed insights and metrics for react-monaco-editor
@monaco-editor/react
Monaco Editor for React - use the monaco-editor in any React application without needing to use webpack (or rollup/parcel/etc) configuration files / plugins
react-monaco-editor-lite
 
@fluentui/react-monaco-editor
Live React example editing using monaco
@alilc/lowcode-plugin-base-monaco-editor
代码编辑组件,monaco-editor 的低代码适配封装
npm install react-monaco-editor
Typescript
Module System
Node Version
NPM Version
85.5
Supply Chain
89
Quality
83.2
Maintenance
100
Vulnerability
99.6
License
TypeScript (66.76%)
JavaScript (31.89%)
HTML (1.35%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
4,020 Stars
880 Commits
386 Forks
21 Watchers
8 Branches
80 Contributors
Updated on Jul 10, 2025
Latest Version
0.58.0
Package Id
react-monaco-editor@0.58.0
Unpacked Size
57.15 kB
Size
12.15 kB
File Count
23
NPM Version
11.0.0
Node Version
20.18.2
Published on
Jan 25, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
3
Monaco Editor for React.
To build the examples locally, run:
1yarn 2cd example 3yarn 4yarn start
Then open http://localhost:8886
in a browser.
1yarn add react-monaco-editor
1import React from 'react'; 2import { createRoot } from "react-dom/client"; 3import MonacoEditor from 'react-monaco-editor'; 4 5class App extends React.Component { 6 constructor(props) { 7 super(props); 8 this.state = { 9 code: '// type your code...', 10 } 11 } 12 editorDidMount(editor, monaco) { 13 console.log('editorDidMount', editor); 14 editor.focus(); 15 } 16 onChange(newValue, e) { 17 console.log('onChange', newValue, e); 18 } 19 render() { 20 const code = this.state.code; 21 const options = { 22 selectOnLineNumbers: true 23 }; 24 return ( 25 <MonacoEditor 26 width="800" 27 height="600" 28 language="javascript" 29 theme="vs-dark" 30 value={code} 31 options={options} 32 onChange={::this.onChange} 33 editorDidMount={::this.editorDidMount} 34 /> 35 ); 36 } 37} 38 39const container = document.getElementById('root'); 40const root = createRoot(container); 41root.render(<App />);
Add the Monaco Webpack plugin monaco-editor-webpack-plugin
to your webpack.config.js
:
1const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin'); 2module.exports = { 3 plugins: [ 4 new MonacoWebpackPlugin({ 5 // available options are documented at https://github.com/microsoft/monaco-editor/blob/main/webpack-plugin/README.md#options 6 languages: ['json'] 7 }) 8 ] 9};
Sidenote: Monaco Editor uses CSS imports internally, so if you're using CSS Modules in your project - you're likely to get conflict by default. In order to avoid that - separate css-loader for app and monaco-editor package:
1// Specify separate paths 2const path = require('path'); 3const APP_DIR = path.resolve(__dirname, './src'); 4const MONACO_DIR = path.resolve(__dirname, './node_modules/monaco-editor'); 5 6{ 7 test: /\.css$/, 8 include: APP_DIR, 9 use: [{ 10 loader: 'style-loader', 11 }, { 12 loader: 'css-loader', 13 options: { 14 modules: true, 15 namedExport: true, 16 }, 17 }], 18}, { 19 test: /\.css$/, 20 include: MONACO_DIR, 21 use: ['style-loader', 'css-loader'], 22}
All the properties below are optional.
width
width of editor. Defaults to 100%
.
height
height of editor. Defaults to 100%
.
value
value of the auto created model in the editor.
defaultValue
the initial value of the auto created model in the editor.
language
the initial language of the auto created model in the editor.
theme
the theme of the editor
options
refer to Monaco interface IStandaloneEditorConstructionOptions.
overrideServices
refer to Monaco Interface IEditorOverrideServices. It depends on Monaco's internal implementations and may change over time, check github issue for more details.
onChange(newValue, event)
an event emitted when the content of the current model has changed.
editorWillMount(monaco)
an event emitted before the editor mounted (similar to componentWillMount
of React).
editorDidMount(editor, monaco)
an event emitted when the editor has been mounted (similar to componentDidMount
of React).
editorWillUnmount(editor, monaco)
an event emitted before the editor unmount (similar to componentWillUnmount
of React).
Refer to Monaco interface IEditor.
The monaco interfaces available by import
1import { monaco } from 'react-monaco-editor';
Make sure to use the Monaco Webpack plugin or follow the instructions on how to load the ESM version of Monaco.
Using the first parameter of editorDidMount
, or using a ref
(e.g. <MonacoEditor ref="monaco">
) after editorDidMount
event has fired.
Then you can invoke instance methods via this.refs.monaco.editor
, e.g. this.refs.monaco.editor.focus()
to focuses the MonacoEditor instance.
Using this.refs.monaco.editor.getValue()
or via method of Model
instance:
1const model = this.refs.monaco.editor.getModel(); 2const value = model.getValue();
For example, you may want to configure some JSON schemas before editor mounted, then you can go with editorWillMount(monaco)
:
1class App extends React.Component { 2 editorWillMount(monaco) { 3 monaco.languages.json.jsonDefaults.setDiagnosticsOptions({ 4 validate: true, 5 schemas: [{ 6 uri: "http://myserver/foo-schema.json", 7 fileMatch: ['*'], 8 schema: { 9 type: "object", 10 properties: { 11 p1: { 12 enum: [ "v1", "v2"] 13 }, 14 p2: { 15 $ref: "http://myserver/bar-schema.json" 16 } 17 } 18 } 19 }] 20 }); 21 } 22 render() { 23 return ( 24 <MonacoEditor language="json" editorWillMount={this.editorWillMount} /> 25 ); 26 } 27}
Monaco only supports one theme.
1import React from 'react'; 2import { MonacoDiffEditor } from 'react-monaco-editor'; 3 4class App extends React.Component { 5 render() { 6 const code1 = "// your original code..."; 7 const code2 = "// a different version..."; 8 const options = { 9 //renderSideBySide: false 10 }; 11 return ( 12 <MonacoDiffEditor 13 width="800" 14 height="600" 15 language="javascript" 16 original={code1} 17 value={code2} 18 options={options} 19 /> 20 ); 21 } 22}
create-react-app
The easiest way to use the react-monaco-editor
with create-react-app
is to use the react-app-rewired project. For setting it up, the following steps are required:
react-app-rewired
: npm install -D react-app-rewired
react-scripts
by react-app-rewired
in the scripts section of your packages.json
config-overrides.js
in the root directory of your project with the following content:1const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin'); 2 3module.exports = function override(config, env) { 4 config.plugins.push(new MonacoWebpackPlugin({ 5 languages: ['json'] 6 })); 7 return config; 8}
For more information checkout the documentation of react-app-rewired
here.
MIT, see the LICENSE file for detail.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
16 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 1/2 approved changesets -- score normalized to 5
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
17 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More