Fix icon doesn't refresh when changed

This commit is contained in:
Lim Chee Aun 2023-12-23 18:05:30 +08:00
parent 30403f835c
commit 3cab36f24c

View file

@ -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 (
<span