mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 15:05: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);
|
||||
|
||||
useEffect(() => {
|
||||
if (monacoEl && !editor) {
|
||||
setEditor(
|
||||
monaco.editor.create(monacoEl.current!, {
|
||||
if (monacoEl) {
|
||||
setEditor((editor) => {
|
||||
if (editor) return;
|
||||
|
||||
return monaco.editor.create(monacoEl.current!, {
|
||||
value: ['function x() {', '\tconsole.log("Hello world!");', '}'].join('\n'),
|
||||
language: 'typescript'
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return () => editor?.dispose();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue