personal-website/components/server/HybridLink.tsx
Filipe Medeiros 40f7fbf1a1
fix: meta info and more
Signed-off-by: Filipe Medeiros <hello@filipesm.eu>
2023-12-03 12:25:57 +01:00

25 lines
595 B
TypeScript

import Link from 'next/link'
import { type ComponentProps, type PropsWithChildren, forwardRef } from 'react'
export type Props = ComponentProps<typeof Link>
const HybridLink = forwardRef<HTMLAnchorElement, Props>(function HybridLink(
{ href, children, ...rest }: PropsWithChildren<Props>,
ref,
) {
if (href && (typeof href !== 'string' || href.startsWith('/')))
return (
<Link href={href} {...rest} ref={ref}>
{children}
</Link>
)
else
return (
<a href={href} {...rest} ref={ref}>
{children}
</a>
)
})
export default HybridLink