File tree Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Expand file tree Collapse file tree 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> {
625625 let initialIcon ;
626626 let isLoading = false ;
627627
628- // Category 1: cached oui icons
628+ // Define helper function
629+ const getIconAndLoadingStatus = ( type : any ) => {
630+ // Category 1: cached oui icons
629631 if ( isCachedIcon ( type ) ) {
630- initialIcon = iconComponentCache [ type as string ] ;
632+ return { icon : iconComponentCache [ type as string ] , isLoading : false } ;
631633 // Category 2: URL (relative, absolute)
632634 } else if ( isUrl ( type ) ) {
633- initialIcon = type ;
635+ return { icon : type , isLoading : false } ;
634636 // Category 3: non-cached oui icon or new icon
635637 } else if ( typeof type === 'string' ) {
636- isLoading = true ;
637638 this . loadIconComponent ( type as OuiIconType ) ;
639+ return { icon : undefined , isLoading : true } ;
638640 } else {
639641 // Category 4: custom icon component
640- initialIcon = type ;
641642 this . onIconLoad ( ) ;
643+ return { icon : type , isLoading : false } ;
642644 }
645+ } ;
646+
647+ // Use the helper function
648+ const { icon : initialIcon , isLoading } = getIconAndLoadingStatus ( type ) ;
643649
644650 this . state = {
645651 icon : initialIcon ,
You can’t perform that action at this time.
0 commit comments