* feat: get object metadata from backend in Object Detail and New Field - Step 1 Closes #2008 * refactor: add useLazyLoadIcon hook
22 lines
587 B
TypeScript
22 lines
587 B
TypeScript
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 };
|
|
};
|