From 163961c4949af34019409fcb7d01df6cf399f3a1 Mon Sep 17 00:00:00 2001
From: Lim Chee Aun <cheeaun@gmail.com>
Date: Mon, 24 Apr 2023 19:27:12 +0800
Subject: [PATCH] Memoize the Parent

---
 src/components/media.jsx | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/components/media.jsx b/src/components/media.jsx
index 0b32e053..cac624c0 100644
--- a/src/components/media.jsx
+++ b/src/components/media.jsx
@@ -1,5 +1,5 @@
 import { getBlurHashAverageColor } from 'fast-blurhash';
-import { useCallback, useRef, useState } from 'preact/hooks';
+import { useCallback, useMemo, useRef, useState } from 'preact/hooks';
 import QuickPinchZoom, { make3dTransformValue } from 'react-quick-pinch-zoom';
 
 import Icon from './icon';
@@ -79,7 +79,10 @@ function Media({ media, to, showOriginal, autoAnimate, onClick = () => {} }) {
     onUpdate,
   };
 
-  const Parent = to ? (props) => <Link to={to} {...props} /> : 'div';
+  const Parent = useMemo(
+    () => (to ? (props) => <Link to={to} {...props} /> : 'div'),
+    [to],
+  );
 
   if (type === 'image' || (type === 'unknown' && previewUrl && url)) {
     // Note: type: unknown might not have width/height