Last active
March 5, 2022 22:39
-
-
Save plbstl/01258027147385801b55ff0e3fb864a7 to your computer and use it in GitHub Desktop.
Make Nextjs link work with Adobe Spectrum link
This file contains 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 { Link as SpectrumLink } from "@adobe/react-spectrum" | |
import type { SpectrumLinkProps } from "@react-types/link" | |
import NextLink, { LinkProps as NextLinkProps } from "next/link" | |
import { AnchorHTMLAttributes, forwardRef } from "react" | |
type _LinkProps = AnchorHTMLAttributes<HTMLAnchorElement> & SpectrumLinkProps | |
const _Link = forwardRef<HTMLAnchorElement, _LinkProps>(function _Link(props, ref) { | |
const { children, href, target, rel, ...rest } = props | |
return ( | |
<SpectrumLink {...rest}> | |
<a href={href} ref={ref} target={target} rel={rel}> | |
{children} | |
</a> | |
</SpectrumLink> | |
) | |
}) | |
type LinkProps = _LinkProps & { href: NextLinkProps["href"] } | |
function Link({ href, ...rest }: LinkProps) { | |
return ( | |
<NextLink href={href} passHref> | |
<_Link {...rest} /> | |
</NextLink> | |
) | |
} | |
export default Link |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment