PdfDocumentLoader is a React component responsible for loading and managing a PDF document.
It handles the asynchronous loading process, displays loading progress, and manages errors.
Props:
pdfLoaderProps: An object containing properties to configure the PDF loading behavior.
url: The URL of the PDF file to load.
data: The binary data of the PDF file to load.
onProgress: A callback function to be called with the loading progress.
beforeLoaded: A React element to display before the PDF is fully loaded.
errorMessage: A React element to display if an error occurs during loading.
State:
pdfDocument: The loaded PDF document proxy, or null if not loaded.
error: An error object if loading fails, or null if successful.
progress: An object containing the number of bytes loaded and the total number of bytes.
The component uses the useEffect hook to handle side effects such as loading the PDF
when the component mounts or when the url or data prop changes. It also cleans up
any existing PDF document when the component unmounts or when the props change.
The component renders a PdfDocument.Provider that wraps its children, providing the
loaded PDF document proxy to them via React context.
PdfDocumentLoader is a React component responsible for loading and managing a PDF document. It handles the asynchronous loading process, displays loading progress, and manages errors.
Props:
State:
The component uses the
useEffecthook to handle side effects such as loading the PDF when the component mounts or when theurlordataprop changes. It also cleans up any existing PDF document when the component unmounts or when the props change.The component renders a
PdfDocument.Providerthat wraps its children, providing the loaded PDF document proxy to them via React context.