feat: add SettingsObjectFieldPreview and SettingsObjectFieldPreviewCard (#2376)
* feat: add SettingsObjectFieldPreview Closes #2343 * feat: add SettingsObjectFieldPreviewCard Closes #2349 * Fix ci * Fix tests * Fix tests --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -2,20 +2,21 @@ import { useEffect, useState } from 'react';
|
||||
|
||||
import { IconComponent } from '@/ui/display/icon/types/IconComponent';
|
||||
|
||||
import { useLazyLoadIcons } from './useLazyLoadIcons';
|
||||
|
||||
export const useLazyLoadIcon = (iconKey: string) => {
|
||||
const { isLoadingIcons, icons } = useLazyLoadIcons();
|
||||
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]);
|
||||
if (!isLoadingIcons) {
|
||||
setIcon(icons[iconKey]);
|
||||
setIsLoadingIcon(false);
|
||||
}
|
||||
}, [iconKey, icons, isLoadingIcons]);
|
||||
|
||||
return { Icon, isLoadingIcon };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user