From 266a9315f3244f46e9ad30ef40a679eb18a68401 Mon Sep 17 00:00:00 2001 From: Rikki Schulte Date: Fri, 20 Oct 2023 23:43:53 +0200 Subject: [PATCH] simple example of next and turbo --- examples/next-turbo/src/app/editor.tsx | 8 ++++++-- examples/next-turbo/src/app/page.tsx | 1 - 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/next-turbo/src/app/editor.tsx b/examples/next-turbo/src/app/editor.tsx index ccc57c5..2afdd3a 100644 --- a/examples/next-turbo/src/app/editor.tsx +++ b/examples/next-turbo/src/app/editor.tsx @@ -12,7 +12,7 @@ import { oneDarkHighlightStyle, oneDark } from "@codemirror/theme-one-dark"; import { JSONSchema7 } from "json-schema"; // sample data -import { jsonText, json5Text } from "../../../../dev/sample-text"; +import { jsonText } from "../../../../dev/sample-text"; import packageJsonSchema from "../../../../dev/package.schema.json"; // json4 @@ -41,6 +41,9 @@ const commonExtensions = [ syntaxHighlighting(oneDarkHighlightStyle), ]; +// because of react strict mode +let isRendered = false; + export const Editor = () => { const editorRef = useRef(null); const state = EditorState.create({ @@ -49,11 +52,12 @@ export const Editor = () => { }); useEffect(() => { - if (editorRef.current) { + if (editorRef.current && !isRendered) { new EditorView({ state, parent: editorRef.current!, }); + isRendered = true; } return () => { diff --git a/examples/next-turbo/src/app/page.tsx b/examples/next-turbo/src/app/page.tsx index 05fc887..3582b53 100644 --- a/examples/next-turbo/src/app/page.tsx +++ b/examples/next-turbo/src/app/page.tsx @@ -1,6 +1,5 @@ "use client"; -import Image from "next/image"; import styles from "./page.module.css"; import dynamic from "next/dynamic";