import * as monaco from 'monaco-editor'; import React, { useEffect, useRef } from 'react'; import { Container } from './styles'; const Editor = ({ value }: EditorProps) => { const divEl = useRef(null); const editorRef = useRef(); useEffect(() => { let editor = editorRef.current; if (divEl.current) { editor = monaco.editor.create(divEl.current, { value: value.current || '', useShadowDOM: true, theme: 'vs-dark', automaticLayout: true, fontSize: 16, minimap: { enabled: false, }, language: 'yaml', }); } editor?.getModel()?.onDidChangeContent(() => { value.current = editor?.getValue() || ''; }); return () => { if (editor) { editor.dispose(); } }; }, [value]); return ; }; interface EditorProps { value: React.MutableRefObject; } export default Editor;