Add lazy loading

This commit is contained in:
Sam Wright 2024-06-20 01:36:07 +10:00
parent 684399bacb
commit 1e5a1622fb
3 changed files with 6 additions and 6 deletions

View File

@ -1,6 +1,6 @@
import { isDesktop } from "react-device-detect";
import { MonacoEditor } from "./MonacoEditor";
import { CodeMirrorEditor } from "./CodeMirrorEditor";
import { lazy } from "react";
import MonacoEditor from "./MonacoEditor";
/**
* Provides an interface for a Code Editor, to enable easy swapping between different implementations
@ -18,6 +18,6 @@ export type CodeEditorProps = {
*
* It would be great to revisit this in in the future if/when Monaco improves mobile support.
*/
export const CodeEditor: (props: CodeEditorProps) => JSX.Element = isDesktop
export const CodeEditor: (props: CodeEditorProps) => React.ReactNode = isDesktop
? MonacoEditor
: CodeMirrorEditor;
: lazy(() => import("./CodeMirrorEditor"));

View File

@ -41,7 +41,7 @@ import { useTheme } from "@/context/theme-provider";
* Uses `CodeMirror` as a code editor implementation.
* Currently doesn't support yaml schema validation or linting.
*/
export function CodeMirrorEditor({
export default function CodeMirrorEditor({
initialContent,
onDidChangeContent,
}: Omit<CodeEditorProps, "schemaUrl">) {

View File

@ -4,7 +4,7 @@ import { configureMonacoYaml } from "monaco-yaml";
import { useEffect, useRef, useState } from "react";
import type { CodeEditorProps } from "./CodeEditor";
export function MonacoEditor({
export default function MonacoEditor({
initialContent,
yamlSchemaUrl,
onDidChangeContent,