Created
August 11, 2022 05:56
-
-
Save Phryxia/304e4320635e7e01646f5357bf2ea910 to your computer and use it in GitHub Desktop.
Proxying component for Next.js Link
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 { cloneElement, PropsWithChildren, ReactElement } from 'react' | |
| export default function Link({ children, href }: PropsWithChildren<any>) { | |
| if (typeof children === 'object') { | |
| const reactChild = children as ReactElement | |
| if (reactChild.type === 'a' && href) { | |
| return cloneElement(reactChild, { href }) | |
| } | |
| } | |
| return children | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment