I'm encountering a problem with my code while attempting to create a PDFViewer component in React (using TypeScript) with the react-pdf library. Despite my efforts, it seems to be failing, and I'm struggling to understand why. I've come across some solutions online, but they involve modifying the index.d.ts file, and I'm fairly certain there must be another solution available.
Here's my code:
import React, { useState } from "react";
import { Document, Page } from "@react-pdf/renderer";
const PDFViewer: React.FC = () => {
const [numPages, setNumPages] = useState<number | null>(null);
const [pageNumber, setPageNumber] = useState<number>(1);
const onDocumentLoadSuccess = ({ numPages }: any) => {
setNumPages(numPages);
};
return (
<div>
<Document
file="https://www.cisco.com/c/fr_ca/support/docs/contact-center/remote-expert-mobile/214321-remote-expert-mobile-reset-web-gateway-a.pdf"
onLoadSuccess={onDocumentLoadSuccess}
>
<Page pageNumber={pageNumber} />
</Document>
<p>
Page {pageNumber} of {numPages}
</p>
</div>
);
};
export default PDFViewer;
Here's the error:
No overload matches this call.
Overload 1 of 2, '(props: PropsWithChildren<DocumentProps>): Document', gave the following error.
Type '{ children: Element; file: string; onLoadSuccess: ({ numPages }: any) => void; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Document> & Readonly<PropsWithChildren<DocumentProps>>'.
Property 'file' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<Document> & Readonly<PropsWithChildren<DocumentProps>>'.
Overload 2 of 2, '(props: PropsWithChildren<DocumentProps>, context: any): Document', gave the following error.
Type '{ children: Element; file: string; onLoadSuccess: ({ numPages }: any) => void; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Document> & Readonly<PropsWithChildren<DocumentProps>>'.
Property 'file' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<Document> & Readonly<PropsWithChildren<DocumentProps>>'.ts(2769)