@@ -44,23 +44,24 @@ import "@blocknote/core/style.css";
4444
4545export default function App() {
4646 // Stores the editor's contents as Markdown.
47- const [markdown, setMarkdown] = useState <string | null >( null );
47+ const [markdown, setMarkdown] = useState <string >( " " );
4848
4949 // Creates a new editor instance.
50- const editor = useBlockNote ({
50+ const editor: BlockNoteEditor | null = useBlockNote ({
5151 // Listens for when the editor's contents change.
5252 onEditorContentChange : (editor : BlockNoteEditor ) => {
5353 // Converts the editor's contents from Block objects to Markdown and
5454 // saves them.
5555 const saveBlocksAsMarkdown = async () => {
56- const markdown = await editor .blocksToMarkdown (editor .topLevelBlocks );
56+ const markdown: string =
57+ await editor .blocksToMarkdown (editor .topLevelBlocks );
5758 setMarkdown (markdown );
5859 };
5960 saveBlocksAsMarkdown ();
6061 }
6162 });
6263
63- // Renders a BlockNote editor, and its contents as Markdown below.
64+ // Renders the editor instance , and its contents as Markdown below.
6465 return (
6566 <div >
6667 < BlockNoteView editor = {editor } / >
@@ -98,11 +99,14 @@ Tries to create `Block` and `InlineNode` objects based on Markdown syntax, thoug
9899
99100``` typescript /App.tsx
100101import { useEffect , useState } from " react" ;
101- import { BlockNoteEditor } from " @blocknote/core" ;
102+ import { BlockNoteEditor , Block } from " @blocknote/core" ;
102103import { BlockNoteView , useBlockNote } from " @blocknote/react" ;
103104import " @blocknote/core/style.css" ;
104105
105106export default function App() {
107+ // Stores the current Markdown content.
108+ const [markdown, setMarkdown] = useState <string >(" " );
109+
106110 // Creates a new editor instance.
107111 const editor: BlockNoteEditor | null = useBlockNote ({
108112 // Makes the editor non-editable.
@@ -111,23 +115,20 @@ export default function App() {
111115 },
112116 })
113117
114- // Stores the current Markdown content.
115- const [markdown, setMarkdown] = useState <string >(" " );
116-
117118 useEffect (() => {
118119 if (editor ) {
119120 // Whenever the current Markdown content changes, converts it to an array
120121 // of Block objects and replaces the editor's content with them.
121122 const getBlocks = async () => {
122- const blocks = await editor .markdownToBlocks (markdown );
123+ const blocks: Block [] = await editor .markdownToBlocks (markdown );
123124 editor .replaceBlocks (editor .topLevelBlocks , blocks );
124125 };
125126 getBlocks ();
126127 }
127128 }, [editor , markdown ]);
128129
129- // Renders a text area for you to write/paste Markdown in and a BlockNote
130- // editor below, which displays the current Markdown as blocks.
130+ // Renders a text area for you to write/paste Markdown in, and the editor
131+ // instance below, which displays the current Markdown as blocks.
131132 return (
132133 <div >
133134 < textarea
@@ -179,23 +180,23 @@ import "@blocknote/core/style.css";
179180
180181export default function App() {
181182 // Stores the editor's contents as HTML.
182- const [html, setHTML] = useState <string | null >( null );
183+ const [html, setHTML] = useState <string >( " " );
183184
184185 // Creates a new editor instance.
185- const editor = useBlockNote ({
186+ const editor: BlockNoteEditor | null = useBlockNote ({
186187 // Listens for when the editor's contents change.
187188 onEditorContentChange : (editor : BlockNoteEditor ) => {
188189 // Converts the editor's contents from Block objects to HTML and saves
189190 // them.
190191 const saveBlocksAsHTML = async () => {
191- const html = await editor .blocksToHTML (editor .topLevelBlocks );
192+ const html: string = await editor .blocksToHTML (editor .topLevelBlocks );
192193 setHTML (html );
193194 };
194195 saveBlocksAsHTML ();
195196 }
196197 });
197198
198- // Renders a BlockNote editor, and its contents as HTML below.
199+ // Renders the editor instance , and its contents as HTML below.
199200 return (
200201 <div >
201202 < BlockNoteView editor = {editor } / >
@@ -233,11 +234,14 @@ Tries to create `Block` objects out of any HTML block-level elements, and `Inlin
233234
234235``` typescript /App.tsx
235236import { useEffect , useState } from " react" ;
236- import { BlockNoteEditor } from " @blocknote/core" ;
237+ import { BlockNoteEditor , Block } from " @blocknote/core" ;
237238import { BlockNoteView , useBlockNote } from " @blocknote/react" ;
238239import " @blocknote/core/style.css" ;
239240
240241export default function App() {
242+ // Stores the current HTML content.
243+ const [html, setHTML] = useState <string >(" " );
244+
241245 // Creates a new editor instance.
242246 const editor: BlockNoteEditor | null = useBlockNote ({
243247 // Makes the editor non-editable.
@@ -246,22 +250,19 @@ export default function App() {
246250 },
247251 })
248252
249- // Stores the current HTML content.
250- const [html, setHTML] = useState <string >(" " );
251-
252253 useEffect (() => {
253254 if (editor ) {
254255 // Whenever the current HTML content changes, converts it to an array of
255256 // Block objects and replaces the editor's content with them.
256257 const getBlocks = async () => {
257- const blocks = await editor .HTMLToBlocks (html );
258+ const blocks: Block [] = await editor .HTMLToBlocks (html );
258259 editor .replaceBlocks (editor .topLevelBlocks , blocks );
259260 };
260261 getBlocks ();
261262 }
262263 }, [editor , html ]);
263264
264- // Renders a text area for you to write/paste HTML in and a BlockNote editor
265+ // Renders a text area for you to write/paste HTML in, and the editor instance
265266 // below, which displays the current HTML as blocks.
266267 return (
267268 <div >
0 commit comments