From 46e92a88cc7b2f350aafb696ad8c41cffb4954c0 Mon Sep 17 00:00:00 2001 From: phartenfeller Date: Sun, 4 Feb 2024 22:40:14 +0100 Subject: [PATCH] lazy load react pinch --- src/components/blog/BlogImagePopup.jsx | 50 ++++++++++++++++---------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/src/components/blog/BlogImagePopup.jsx b/src/components/blog/BlogImagePopup.jsx index 9be9010..09dc078 100644 --- a/src/components/blog/BlogImagePopup.jsx +++ b/src/components/blog/BlogImagePopup.jsx @@ -1,8 +1,18 @@ -import React, { Fragment } from 'react'; +import React, { Fragment, Suspense } from 'react'; import { Dialog, Transition } from '@headlessui/react'; -import { TransformWrapper, TransformComponent } from 'react-zoom-pan-pinch'; import useImagePreview from '../../state/useImagePreview'; +const TransformWrapper = React.lazy(() => + import('react-zoom-pan-pinch').then((module) => ({ + default: module.TransformWrapper, + })) +); +const TransformComponent = React.lazy(() => + import('react-zoom-pan-pinch').then((module) => ({ + default: module.TransformComponent, + })) +); + export default function BlogImagePopup() { const { isOpen, close, clear, imgSrc, alt, width, height } = useImagePreview(); @@ -73,23 +83,25 @@ export default function BlogImagePopup() {
- - - {alt} - - + Loading...
}> + + + {alt} + + +