Fix icon doesn't refresh when changed

pull/375/head
Lim Chee Aun 2023-12-23 18:05:30 +08:00
rodzic 30403f835c
commit 3cab36f24c
1 zmienionych plików z 5 dodań i 3 usunięć

Wyświetl plik

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