mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 05:12:39 +00:00
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:
@@ -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;
|
||||
|
Reference in New Issue
Block a user