feat: get object metadata from backend in Object Detail and New Field… (#2122)
* feat: get object metadata from backend in Object Detail and New Field - Step 1 Closes #2008 * refactor: add useLazyLoadIcon hook
This commit is contained in:
21
front/src/modules/ui/input/hooks/useLazyLoadIcon.ts
Normal file
21
front/src/modules/ui/input/hooks/useLazyLoadIcon.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
import { IconComponent } from '@/ui/display/icon/types/IconComponent';
|
||||
|
||||
export const useLazyLoadIcon = (iconKey: string) => {
|
||||
const [Icon, setIcon] = useState<IconComponent | undefined>();
|
||||
const [isLoadingIcon, setIsLoadingIcon] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
if (!iconKey) return;
|
||||
|
||||
import(`@tabler/icons-react/dist/esm/icons/${iconKey}.js`).then(
|
||||
(lazyLoadedIcon) => {
|
||||
setIcon(lazyLoadedIcon.default);
|
||||
setIsLoadingIcon(false);
|
||||
},
|
||||
);
|
||||
}, [iconKey]);
|
||||
|
||||
return { Icon, isLoadingIcon };
|
||||
};
|
||||
17
front/src/modules/ui/input/hooks/useLazyLoadIcons.ts
Normal file
17
front/src/modules/ui/input/hooks/useLazyLoadIcons.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
import { IconComponent } from '@/ui/display/icon/types/IconComponent';
|
||||
|
||||
export const useLazyLoadIcons = () => {
|
||||
const [icons, setIcons] = useState<Record<string, IconComponent>>({});
|
||||
const [isLoadingIcons, setIsLoadingIcons] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
import('../constants/icons').then((lazyLoadedIcons) => {
|
||||
setIcons(lazyLoadedIcons);
|
||||
setIsLoadingIcons(false);
|
||||
});
|
||||
}, []);
|
||||
|
||||
return { icons, isLoadingIcons };
|
||||
};
|
||||
Reference in New Issue
Block a user