Merge pull request #3390 from tr3ysmith/patch-1

Fix possible duplicate of editors in vite sample
This commit is contained in:
Henning Dieterichs 2023-01-31 12:50:41 +01:00 committed by GitHub
commit c92637e1f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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();