mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 19:42:56 +01:00
24 lines
725 B
TypeScript
24 lines
725 B
TypeScript
import { VFC, useRef, useState, useEffect } from "react";
|
|
import * as monaco from "monaco-editor/esm/vs/editor/editor.api";
|
|
import styles from "./Editor.module.css";
|
|
|
|
export const Editor: VFC = () => {
|
|
const [editor, setEditor] =
|
|
useState<monaco.editor.IStandaloneCodeEditor | null>(null);
|
|
const monacoEl = useRef(null);
|
|
|
|
useEffect(() => {
|
|
if (monacoEl && !editor) {
|
|
setEditor(
|
|
monaco.editor.create(monacoEl.current!, {
|
|
value: ['function x() {', '\tconsole.log("Hello world!");', '}'].join('\n'),
|
|
language: "typescript",
|
|
})
|
|
);
|
|
}
|
|
|
|
return () => editor?.dispose();
|
|
}, [monacoEl.current]);
|
|
|
|
return <div className={styles.Editor} ref={monacoEl}></div>;
|
|
};
|