Skip to content

Commit

Permalink
fix: onMount prop conflict with ReactMonacoEditor component (#359)
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianoventura authored Nov 21, 2024
1 parent 0678c9b commit 5faa040
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/components/Monaco/ReactMonacoEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useTheme } from '@/hooks/useTheme'
import { Editor, EditorProps, loader } from '@monaco-editor/react'
import { Editor, EditorProps, loader, Monaco } from '@monaco-editor/react'
import * as monaco from 'monaco-editor'
import { EditorToolbar, ToolbarState } from './EditorToolbar'
import { useMemo, useState } from 'react'
Expand Down Expand Up @@ -56,6 +56,17 @@ export function ReactMonacoEditor({
return true
}, [editor])

const handleEditorMount = (
editor: monaco.editor.IStandaloneCodeEditor,
monaco: Monaco
) => {
setEditor(editor)

if (props.onMount) {
props.onMount(editor, monaco)
}
}

return (
<Flex height="100%" width="100%" direction="column">
{showToolbar && (
Expand All @@ -71,7 +82,7 @@ export function ReactMonacoEditor({
...props.options,
wordWrap: toolbarState.wordWrap,
}}
onMount={(editor) => setEditor(editor)}
onMount={handleEditorMount}
theme={theme === 'dark' ? 'vs-dark' : 'k6-studio-light'}
/>
</Flex>
Expand Down

0 comments on commit 5faa040

Please sign in to comment.