Skip to content

Commit 6db49b9

Browse files
docs: fix "Displaying Document JSON" example (#1943)
1 parent e2b63e8 commit 6db49b9

File tree

1 file changed

+6
-3
lines changed
  • examples/01-basic/02-block-objects/src

1 file changed

+6
-3
lines changed

examples/01-basic/02-block-objects/src/App.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import "@blocknote/core/fonts/inter.css";
33
import { BlockNoteView } from "@blocknote/mantine";
44
import "@blocknote/mantine/style.css";
55
import { useCreateBlockNote } from "@blocknote/react";
6-
import { useState } from "react";
6+
import { useEffect, useState } from "react";
77

88
import "./styles.css";
99

@@ -32,6 +32,9 @@ export default function App() {
3232
],
3333
});
3434

35+
// Sets the initial document JSON
36+
useEffect(() => setBlocks(editor.document), []);
37+
3538
// Renders the editor instance and its document JSON.
3639
return (
3740
<div className={"wrapper"}>
@@ -40,15 +43,15 @@ export default function App() {
4043
<BlockNoteView
4144
editor={editor}
4245
onChange={() => {
43-
// Saves the document JSON to state.
46+
// Sets the document JSON whenever the editor content changes.
4447
setBlocks(editor.document);
4548
}}
4649
/>
4750
</div>
4851
<div>Document JSON:</div>
4952
<div className={"item bordered"}>
5053
<pre>
51-
<code>{JSON.stringify(editor.document, null, 2)}</code>
54+
<code>{JSON.stringify(blocks, null, 2)}</code>
5255
</pre>
5356
</div>
5457
</div>

0 commit comments

Comments
 (0)