Skip to content

Commit a90ae4d

Browse files
committed
fix: get pdf example working again
1 parent cd2b7c6 commit a90ae4d

File tree

2 files changed

+318
-286
lines changed

2 files changed

+318
-286
lines changed

examples/05-interoperability/05-converting-blocks-to-pdf/src/App.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ import {
2525
withMultiColumn,
2626
} from "@blocknote/xl-multi-column";
2727
import { PDFViewer } from "@react-pdf/renderer";
28-
import { useEffect, useMemo, useState } from "react";
28+
import { useEffect, useMemo, useReducer, useState } from "react";
2929

3030
import "./styles.css";
3131

3232
export default function App() {
3333
// Stores the editor's contents as HTML.
3434
const [pdfDocument, setPDFDocument] = useState<any>();
35+
const [renders, forceRerender] = useReducer((s) => s + 1, 0);
3536

3637
// Creates a new editor instance with some initial content.
3738
const editor = useCreateBlockNote({
@@ -396,6 +397,7 @@ export default function App() {
396397
// Converts the editor's contents from Block objects to HTML and store to state.
397398
const pdfDocument = await exporter.toReactPDFDocument(editor.document);
398399
setPDFDocument(pdfDocument);
400+
forceRerender();
399401

400402
// const blob = await ReactPDF.pdf(pdfDocument).toBlob();
401403
};
@@ -417,7 +419,9 @@ export default function App() {
417419
</BlockNoteView>
418420
</div>
419421
<div className="pdf">
420-
<PDFViewer width={"100%"}>{pdfDocument}</PDFViewer>
422+
<PDFViewer width={"100%"} key={renders}>
423+
{pdfDocument}
424+
</PDFViewer>
421425
</div>
422426
</div>
423427
);

0 commit comments

Comments
 (0)