mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
20 lines
541 B
TypeScript
20 lines
541 B
TypeScript
import { useState } from 'react';
|
|
import useAsyncEffect, { AsyncEffectEvent } from '@joplin/lib/hooks/useAsyncEffect';
|
|
import PdfDocument from '../PdfDocument';
|
|
|
|
|
|
const usePdfDocument = (pdfPath: string) => {
|
|
const [pdfDocument, setPdfDocument] = useState<PdfDocument>(null);
|
|
|
|
useAsyncEffect(async (event: AsyncEffectEvent) => {
|
|
const pdfData = new PdfDocument(document);
|
|
await pdfData.loadDoc(pdfPath);
|
|
if (event.cancelled) return;
|
|
setPdfDocument(pdfData);
|
|
}, [pdfPath]);
|
|
|
|
return pdfDocument;
|
|
};
|
|
|
|
export default usePdfDocument;
|