Created
March 31, 2022 02:56
-
-
Save Houserqu/95d22e1cb69c3e3242077eb9cdf75457 to your computer and use it in GitHub Desktop.
react-monaco-editor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect, useRef } from "react" | |
import * as monaco from 'monaco-editor' | |
interface Props { | |
defaultValue?: string | |
height?: number | |
onChange?: any | |
} | |
export default function Editor({defaultValue, height = 500, onChange}: Props) { | |
const editorRef = useRef<any>(null) | |
useEffect(() => { | |
const editor = monaco.editor.create(editorRef.current, { | |
value: defaultValue, | |
language: 'javascript', | |
automaticLayout: true, | |
}); | |
editor.onDidChangeModelContent((event) => { | |
onChange(editor.getValue(), event); | |
}); | |
}, []) | |
return ( | |
<div ref={editorRef} style={{height}}></div> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment