From 7f60d865158b75cac597a106af12f82adc68cefa Mon Sep 17 00:00:00 2001 From: Mikael Brevik Date: Wed, 18 Dec 2024 10:26:14 +0100 Subject: [PATCH] fix: avoid crashing image if null --- src/components/image/SanityImage.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/components/image/SanityImage.tsx b/src/components/image/SanityImage.tsx index 7d87cff24..2a143e71c 100644 --- a/src/components/image/SanityImage.tsx +++ b/src/components/image/SanityImage.tsx @@ -29,8 +29,12 @@ const useNextSanityGlobalImage = ( useState(null); useEffect(() => { - fetch(studioImage.src).then((r) => r.ok && setGlobalImage(studioImage)); - fetch(sharedImage.src).then((r) => r.ok && setGlobalImage(sharedImage)); + if (studioImage) { + fetch(studioImage.src).then((r) => r.ok && setGlobalImage(studioImage)); + } + if (sharedImage) { + fetch(sharedImage.src).then((r) => r.ok && setGlobalImage(sharedImage)); + } }, [studioImage, sharedImage]); return globalImage;