usePDF Web only

React-pdf now ships a hook called usePDF that enables accessing all PDF creation capabilities via a React hook API. This is great if you need more control over how the document gets rendered or how often it's updated.


const [instance, update] = usePDF({ document });


Prop nameDescriptionDefault
documentDocument's root elementundefined

Instance object

Prop nameDescriptionDefault
urlRendered document blog url. Null if loading or erroredundefined
blobRendered document blob instance. Null if loading or erroredundefined
loadingLoading state. It's true if current render is in placefalse
errorError message if rendering failedundefined

Update function

Used to trigger a document re-render. By default, changing the document instance does not triggers a new PDF file creation. This is especially helpful when rendering a download button or something similar, where you might want to render the document right before the action gets triggered.

The update function takes the new document and does not return anything.

For more information about how this hook is used please refer to the Using the usePDF hook section

← SVG Images