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

20 lines
541 B
TypeScript
Raw Normal View History

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;