From 3cab36f24cccd1fbe61583e6cfc106c50c378cc8 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Sat, 23 Dec 2023 18:05:30 +0800 Subject: [PATCH] Fix icon doesn't refresh when changed --- src/components/icon.jsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/components/icon.jsx b/src/components/icon.jsx index c9850506..a5fecc5f 100644 --- a/src/components/icon.jsx +++ b/src/components/icon.jsx @@ -1,5 +1,5 @@ import { memo } from 'preact/compat'; -import { useEffect, useState } from 'preact/hooks'; +import { useEffect, useRef, useState } from 'preact/hooks'; const SIZES = { s: 12, @@ -127,14 +127,16 @@ function Icon({ } const [iconData, setIconData] = useState(ICONDATA[icon]); + const currentIcon = useRef(icon); useEffect(() => { - if (iconData) return; + if (iconData && currentIcon.current === icon) return; (async () => { const iconB = await iconBlock(); setIconData(iconB.default); ICONDATA[icon] = iconB.default; })(); - }, [iconData, icon, iconBlock]); + currentIcon.current = icon; + }, [icon]); return (