From d4174b6c588783cc00e520407a0a014dd49433a6 Mon Sep 17 00:00:00 2001 From: Wojciech Maj Date: Wed, 7 Jun 2023 13:18:22 +0200 Subject: [PATCH] Remove getPageProps, memoize customTextRenderer and onPageClick --- test/Test.tsx | 50 +++++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/test/Test.tsx b/test/Test.tsx index a83b1ffc2..10af3c4dd 100644 --- a/test/Test.tsx +++ b/test/Test.tsx @@ -114,12 +114,23 @@ export default function Test() { [], ); + const onPageClick = useCallback( + (event: React.MouseEvent, page: PDFPageProxy | false | undefined) => + console.log('Clicked a page', { event, page }), + [], + ); + const onItemClick = useCallback((args: { pageNumber: number }) => { console.log('Clicked an item', args); const { pageNumber: nextPageNumber } = args; setPageNumber(nextPageNumber); }, []); + const customTextRenderer = useCallback( + ({ str }: { str: string }) => str.replace(/ipsum/g, (value) => `${value}`), + [], + ); + useEffect(() => { (async () => { const nextFileForProps = await (async () => { @@ -197,29 +208,6 @@ export default function Test() { const nextPage = useCallback(() => changePage(1), [changePage]); - function getPageProps() { - return { - canvasBackground, - className: 'custom-classname-page', - devicePixelRatio, - height: pageHeight, - onClick: (event: React.MouseEvent, page: PDFPageProxy | false | undefined) => - console.log('Clicked a page', { event, page }), - onRenderSuccess: onPageRenderSuccess, - renderAnnotationLayer, - renderForms, - renderMode, - renderTextLayer, - scale: pageScale, - width: pageWidth, - customTextRenderer: useCustomTextRenderer - ? ({ str }: { str: string }) => str.replace(/ipsum/g, (value) => `${value}`) - : undefined, - }; - } - - const pageProps = getPageProps(); - const documentProps = { externalLinkTarget, file: fileForProps, @@ -227,6 +215,22 @@ export default function Test() { rotate, }; + const pageProps = { + canvasBackground, + className: 'custom-classname-page', + customTextRenderer: useCustomTextRenderer ? customTextRenderer : undefined, + devicePixelRatio, + height: pageHeight, + onClick: onPageClick, + onRenderSuccess: onPageRenderSuccess, + renderAnnotationLayer, + renderForms, + renderMode, + renderTextLayer, + scale: pageScale, + width: pageWidth, + }; + return (