fix: monaco theme lost if re-render

Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
Innei 2023-04-14 00:07:28 +08:00
parent f4956ea294
commit 9a25ebc628
No known key found for this signature in database
GPG Key ID: 0F62D33977F021F7
1 changed files with 7 additions and 1 deletions

View File

@ -1,7 +1,13 @@
import Editor, { EditorProps } from "@monaco-editor/react"
import { useMonacoTheme } from "./use-theme"
import { useMediaStore } from "~/hooks/useDarkMode"
export function MonacoEditor(props: EditorProps) {
useMonacoTheme()
return <Editor {...props} />
const isDark = useMediaStore((state) => state.isDark)
return (
// define initial theme
<Editor {...props} theme={props.theme ?? (isDark ? "dark" : "light")} />
)
}