react-pdf-js
react-pdf-js copied to clipboard
Two news
Hi, @mikecousins, @ksocha, there are two news: first there are lots of changes for this year in pdf-js and we almost don't need custom pdfjs-dist
since original has partly typings support out of the box.
And I found a huge bug for cases when you have number of pdfs at page or user have to move from page to page w/ a lot of pdfs. We don't do a clean up and don't terminate dedicated worker after pdf will be unmounded. Luckily it could be fixed easily:
...
const documentLoadingTask = useRef<any/*pdfjs.PDFDocumentLoadingTask*/ | null>(null);
...
useEffect(() => () => {
// we must call `PDFDocumentLoadingTask.destroy` method to clean-up after a document, since otherwise some resources
// may not be removed as intended
if (documentLoadingTask.current) {
documentLoadingTask.current.destroy()
}
}, [])
...
documentLoadingTask.current = pdfjs.getDocument(config)
documentLoadingTask.current.promise.then(
....
Cheers