mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 12:45:39 +01:00
Merge pull request #3390 from tr3ysmith/patch-1
Fix possible duplicate of editors in vite sample
This commit is contained in:
commit
c92637e1f1
1 changed files with 7 additions and 5 deletions
|
|
@ -7,13 +7,15 @@ export const Editor: VFC = () => {
|
||||||
const monacoEl = useRef(null);
|
const monacoEl = useRef(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (monacoEl && !editor) {
|
if (monacoEl) {
|
||||||
setEditor(
|
setEditor((editor) => {
|
||||||
monaco.editor.create(monacoEl.current!, {
|
if (editor) return;
|
||||||
|
|
||||||
|
return monaco.editor.create(monacoEl.current!, {
|
||||||
value: ['function x() {', '\tconsole.log("Hello world!");', '}'].join('\n'),
|
value: ['function x() {', '\tconsole.log("Hello world!");', '}'].join('\n'),
|
||||||
language: 'typescript'
|
language: 'typescript'
|
||||||
})
|
});
|
||||||
);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return () => editor?.dispose();
|
return () => editor?.dispose();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue