1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-30 10:36:35 +02:00
joplin/packages/pdf-viewer/hooks/usePdfDocument.ts
2022-09-05 12:35:38 +01:00

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;