Created
May 7, 2020 19:14
-
-
Save rahmatrhd/1a669d20badd036618dfb03c15439795 to your computer and use it in GitHub Desktop.
Using material-ui Link with next.js 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 React, { forwardRef } from 'react'; | |
import { | |
Link as MuiLink, | |
LinkProps as MuiLinkProps | |
} from '@material-ui/core'; | |
import NextLink, { LinkProps as NextLinkProps } from 'next/link'; | |
export type LinkProps = NextLinkProps & MuiLinkProps; | |
const LinkComponent = forwardRef<HTMLAnchorElement, LinkProps>(({ | |
href, | |
as, | |
replace, | |
scroll, | |
shallow, | |
passHref, | |
prefetch, | |
...props | |
}, ref) => ( | |
<NextLink | |
href={href} | |
as={as} | |
replace={replace} | |
scroll={scroll} | |
shallow={shallow} | |
passHref={passHref} | |
prefetch={prefetch} | |
> | |
<a ref={ref} {...props} /> | |
</NextLink> | |
)); | |
const Link: React.FC<LinkProps> = props => <MuiLink {...props} component={LinkComponent} />; | |
export default Link; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment