mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-02-16 15:21:48 +03:00
Fix icon doesn't refresh when changed
This commit is contained in:
parent
30403f835c
commit
3cab36f24c
1 changed files with 5 additions and 3 deletions
|
@ -1,5 +1,5 @@
|
||||||
import { memo } from 'preact/compat';
|
import { memo } from 'preact/compat';
|
||||||
import { useEffect, useState } from 'preact/hooks';
|
import { useEffect, useRef, useState } from 'preact/hooks';
|
||||||
|
|
||||||
const SIZES = {
|
const SIZES = {
|
||||||
s: 12,
|
s: 12,
|
||||||
|
@ -127,14 +127,16 @@ function Icon({
|
||||||
}
|
}
|
||||||
|
|
||||||
const [iconData, setIconData] = useState(ICONDATA[icon]);
|
const [iconData, setIconData] = useState(ICONDATA[icon]);
|
||||||
|
const currentIcon = useRef(icon);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (iconData) return;
|
if (iconData && currentIcon.current === icon) return;
|
||||||
(async () => {
|
(async () => {
|
||||||
const iconB = await iconBlock();
|
const iconB = await iconBlock();
|
||||||
setIconData(iconB.default);
|
setIconData(iconB.default);
|
||||||
ICONDATA[icon] = iconB.default;
|
ICONDATA[icon] = iconB.default;
|
||||||
})();
|
})();
|
||||||
}, [iconData, icon, iconBlock]);
|
currentIcon.current = icon;
|
||||||
|
}, [icon]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span
|
<span
|
||||||
|
|
Loading…
Add table
Reference in a new issue