Last active
July 4, 2022 18:58
-
-
Save raynirola/76c2ce440b9431e396a8e1df91dec7cc to your computer and use it in GitHub Desktop.
Wrapper around Nextjs `Link` component to make it work with HeadlessUI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import type { LinkProps } from 'next/link' | |
import type { PropsWithChildren, HTMLProps } from 'react' | |
import Link from 'next/link' | |
import { forwardRef } from 'react' | |
type HeadlessLinkProps = PropsWithChildren<LinkProps & HTMLProps<HTMLAnchorElement>> | |
const HeadlessLink = forwardRef<HTMLAnchorElement, HeadlessLinkProps>((props, ref) => { | |
const { href, children, ...rest } = props | |
return ( | |
<Link href={href}> | |
<a ref={ref} {...rest}> {children} </a> | |
</Link> | |
) | |
}) | |
HeadlessLink.displayName = 'HeadlessLink' | |
export default HeadlessLink |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment