Skip to content

Commit

Permalink
simple example of next and turbo
Browse files Browse the repository at this point in the history
  • Loading branch information
acao committed Oct 20, 2023
1 parent 69d94d3 commit 266a931
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
8 changes: 6 additions & 2 deletions examples/next-turbo/src/app/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -41,6 +41,9 @@ const commonExtensions = [
syntaxHighlighting(oneDarkHighlightStyle),
];

// because of react strict mode
let isRendered = false;

export const Editor = () => {
const editorRef = useRef<HTMLDivElement>(null);
const state = EditorState.create({
Expand All @@ -49,11 +52,12 @@ export const Editor = () => {
});

useEffect(() => {
if (editorRef.current) {
if (editorRef.current && !isRendered) {
new EditorView({
state,
parent: editorRef.current!,
});
isRendered = true;
}

return () => {
Expand Down
1 change: 0 additions & 1 deletion examples/next-turbo/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"use client";

import Image from "next/image";
import styles from "./page.module.css";

import dynamic from "next/dynamic";
Expand Down

0 comments on commit 266a931

Please sign in to comment.