Skip to content

Commit

Permalink
feat: add callback to updateContainer (#2406)
Browse files Browse the repository at this point in the history
* add an optional callback to updateContainer. This is useful so we can figure out when react is done building the page.

* add changeset
  • Loading branch information
JoachimKoenigslieb authored Oct 9, 2023
1 parent a37d927 commit 3b5e1c7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/smooth-dolphins-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@react-pdf/renderer': patch
---

Added an optional callback to the updateContainer method. This allows the user of the pdf instance to know when the update operation is finished in React. As this is an optional argument, no user code should be changed.
2 changes: 1 addition & 1 deletion packages/renderer/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ declare namespace ReactPDF {
toBlob: () => Promise<Blob>;
toBuffer: () => Promise<NodeJS.ReadableStream>;
on: (event: 'change', callback: () => void) => void;
updateContainer: (document: React.ReactElement<any>) => void;
updateContainer: (document: React.ReactElement<any>, callback?: () => void) => void;
removeListener: (event: 'change', callback: () => void) => void;
};

Expand Down
4 changes: 2 additions & 2 deletions packages/renderer/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ const pdf = initialValue => {
renderer = renderer || createRenderer({ onChange });
const mountNode = renderer.createContainer(container);

const updateContainer = doc => {
renderer.updateContainer(doc, mountNode, null);
const updateContainer = (doc, callback) => {
renderer.updateContainer(doc, mountNode, null, callback);
};

if (initialValue) updateContainer(initialValue);
Expand Down

0 comments on commit 3b5e1c7

Please sign in to comment.