mirror of
https://github.com/zhigang1992/react.git
synced 2026-04-29 04:35:32 +08:00
chore: avoid memo override exported component displayName
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user