chore: avoid memo override exported component displayName

This commit is contained in:
unix
2020-04-29 15:11:49 +08:00
parent c53abeca7b
commit 869154175f
78 changed files with 325 additions and 239 deletions

View File

@@ -14,24 +14,23 @@ const defaultProps = {
type NativeAttrs = Omit<React.AnchorHTMLAttributes<any>, keyof Props>
export type UserLinkProps = Props & typeof defaultProps & NativeAttrs
const UserLink = React.memo(
React.forwardRef<HTMLAnchorElement, React.PropsWithChildren<UserLinkProps>>(({
href, className, children, ...props
}, ref: React.Ref<HTMLAnchorElement>) => {
return (
<div className={className} {...props}>
<Link ref={ref} href={href} pure color target="_blank" rel="noopener">
{children}
</Link>
<style jsx>{`
div :global(a:hover) {
opacity: .7;
}
`}</style>
</div>
)
})
)
const UserLink = React.forwardRef<HTMLAnchorElement, React.PropsWithChildren<UserLinkProps>>(({
href, className, children, ...props
}, ref: React.Ref<HTMLAnchorElement>) => {
return (
<div className={className} {...props}>
<Link ref={ref} href={href} pure color target="_blank" rel="noopener">
{children}
</Link>
<style jsx>{`
div :global(a:hover) {
opacity: .7;
}
`}</style>
</div>
)
})
export default withDefaults(UserLink, defaultProps)
const MemoUserLink = React.memo(UserLink)
export default withDefaults(MemoUserLink, defaultProps)

View File

@@ -75,12 +75,11 @@ const User: React.FC<React.PropsWithChildren<UserProps>> = ({
)
}
type UserComponent<P = {}> = React.FC<P> & {
type MemoUserComponent<P = {}> = React.NamedExoticComponent<P> & {
Link: typeof UserLink
}
type ComponentProps = Partial<typeof defaultProps> & Omit<Props, keyof typeof defaultProps> & NativeAttrs
(User as UserComponent<ComponentProps>).defaultProps = defaultProps
User.defaultProps = defaultProps
export default User as UserComponent<ComponentProps>
export default React.memo(User) as MemoUserComponent<ComponentProps>