Hooks
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.
Usage
const [instance, update] = usePDF({ document });
Parameters
Prop name | Description | Default |
---|---|---|
document | Document's root element | undefined |
Instance object
Prop name | Description | Default |
---|---|---|
url | Rendered document blog url. Null if loading or errored | undefined |
blob | Rendered document blob instance. Null if loading or errored | undefined |
loading | Loading state. It's true if current render is in place | false |
error | Error message if rendering failed | undefined |
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 no arguments and does not return anything.
For more information about how this hook is used please refer to the Using the usePDF hook section