From e33f270f1a06df2430b994a920e59f86a3594bd8 Mon Sep 17 00:00:00 2001 From: EnixCoda Date: Thu, 26 Dec 2019 16:40:35 +0800 Subject: [PATCH] refactor(Icon): simplify return value --- src/components/Icon.tsx | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/components/Icon.tsx b/src/components/Icon.tsx index 1407dbc..ec7ef44 100644 --- a/src/components/Icon.tsx +++ b/src/components/Icon.tsx @@ -125,16 +125,19 @@ type Props = { } export function Icon({ type, className = undefined, placeholder, ...otherProps }: Props) { - if (placeholder) return
- const { name, IconComponent } = getSVGIconComponent(type) - const mergedClassName = cx('octicon', name) + let children: React.ReactNode = null + if (!placeholder) { + const { name, IconComponent } = getSVGIconComponent(type) + const mergedClassName = cx('octicon', name) + children = React.createElement(Octicon, { + icon: IconComponent, + className: mergedClassName, + verticalAlign: 'text-bottom', + }) + } return (
- {React.createElement(Octicon, { - icon: IconComponent, - className: mergedClassName, - verticalAlign: 'text-bottom', - })} + {children}
) }