fix: loal file api error (#3637)

* update doc

* fix: loal file api error

* fix: number input import

* feat: icon load
This commit is contained in:
Archer
2025-01-21 16:46:49 +08:00
committed by GitHub
parent 3c97757e4d
commit 946bd20dbf
7 changed files with 34 additions and 94 deletions

View File

@@ -4,13 +4,23 @@ import { Box, Icon } from '@chakra-ui/react';
import { iconPaths } from './constants';
import type { IconNameType } from './type.d';
const iconCache: Record<string, any> = {};
const MyIcon = ({ name, w = 'auto', h = 'auto', ...props }: { name: IconNameType } & IconProps) => {
const [IconComponent, setIconComponent] = useState<any>(null);
useEffect(() => {
if (iconCache[name]) {
setIconComponent(iconCache[name]);
return;
}
iconPaths[name]?.()
.then((icon) => {
setIconComponent({ as: icon.default });
const component = { as: icon.default };
// Store in cache
iconCache[name] = component;
setIconComponent(component);
})
.catch((error) => console.log(error));
}, [name]);
@@ -30,4 +40,4 @@ const MyIcon = ({ name, w = 'auto', h = 'auto', ...props }: { name: IconNameType
);
};
export default React.memo(MyIcon);
export default MyIcon;