mirror of
https://github.com/cheeaun/phanpy.git
synced 2024-11-24 10:15:37 +03:00
Skip useEffect if icon already loaded
This commit is contained in:
parent
b00033129f
commit
5d95d602a7
1 changed files with 11 additions and 5 deletions
|
@ -107,6 +107,8 @@ export const ICONS = {
|
||||||
speak: () => import('@iconify-icons/mingcute/radar-line'),
|
speak: () => import('@iconify-icons/mingcute/radar-line'),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const ICONDATA = {};
|
||||||
|
|
||||||
function Icon({
|
function Icon({
|
||||||
icon,
|
icon,
|
||||||
size = 'm',
|
size = 'm',
|
||||||
|
@ -124,11 +126,15 @@ function Icon({
|
||||||
[iconBlock, rotate, flip] = iconBlock;
|
[iconBlock, rotate, flip] = iconBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
const [iconData, setIconData] = useState(null);
|
const [iconData, setIconData] = useState(ICONDATA[icon]);
|
||||||
useEffect(async () => {
|
useEffect(() => {
|
||||||
const icon = await iconBlock();
|
if (iconData) return;
|
||||||
setIconData(icon.default);
|
(async () => {
|
||||||
}, [iconBlock]);
|
const iconB = await iconBlock();
|
||||||
|
setIconData(iconB.default);
|
||||||
|
ICONDATA[icon] = iconB.default;
|
||||||
|
})();
|
||||||
|
}, [iconData, icon, iconBlock]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span
|
<span
|
||||||
|
|
Loading…
Reference in a new issue