File tree 1 file changed +11
-5
lines changed
1 file changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -625,21 +625,27 @@ export class OuiIcon extends PureComponent<OuiIconProps, State> {
625
625
let initialIcon ;
626
626
let isLoading = false ;
627
627
628
- // Category 1: cached oui icons
628
+ // Define helper function
629
+ const getIconAndLoadingStatus = ( type : any ) => {
630
+ // Category 1: cached oui icons
629
631
if ( isCachedIcon ( type ) ) {
630
- initialIcon = iconComponentCache [ type as string ] ;
632
+ return { icon : iconComponentCache [ type as string ] , isLoading : false } ;
631
633
// Category 2: URL (relative, absolute)
632
634
} else if ( isUrl ( type ) ) {
633
- initialIcon = type ;
635
+ return { icon : type , isLoading : false } ;
634
636
// Category 3: non-cached oui icon or new icon
635
637
} else if ( typeof type === 'string' ) {
636
- isLoading = true ;
637
638
this . loadIconComponent ( type as OuiIconType ) ;
639
+ return { icon : undefined , isLoading : true } ;
638
640
} else {
639
641
// Category 4: custom icon component
640
- initialIcon = type ;
641
642
this . onIconLoad ( ) ;
643
+ return { icon : type , isLoading : false } ;
642
644
}
645
+ } ;
646
+
647
+ // Use the helper function
648
+ const { icon : initialIcon , isLoading } = getIconAndLoadingStatus ( type ) ;
643
649
644
650
this . state = {
645
651
icon : initialIcon ,
You can’t perform that action at this time.
0 commit comments