Browse Source
* docs: fix ssr warning when click anchor
* docs: fix demoWrapper SSR
* chore: try
* Revert "chore: try"
This reverts commit a6e0fe0906
.
pull/41796/head
MadCcc
2 years ago
committed by
GitHub
4 changed files with 37 additions and 4 deletions
@ -0,0 +1,30 @@ |
|||
import type { MouseEvent } from 'react'; |
|||
import React, { forwardRef, startTransition } from 'react'; |
|||
import { useNavigate } from 'dumi'; |
|||
|
|||
export type LinkProps = { |
|||
to?: string; |
|||
children?: React.ReactNode; |
|||
}; |
|||
|
|||
const Link = forwardRef<HTMLAnchorElement, LinkProps>((props, ref) => { |
|||
const { to, children } = props; |
|||
const navigate = useNavigate(); |
|||
|
|||
const handleClick = (e: MouseEvent<HTMLAnchorElement>) => { |
|||
if (!to.startsWith('http')) { |
|||
e.preventDefault(); |
|||
startTransition(() => { |
|||
navigate(to); |
|||
}); |
|||
} |
|||
}; |
|||
|
|||
return ( |
|||
<a ref={ref} href={to} onClick={handleClick}> |
|||
{children} |
|||
</a> |
|||
); |
|||
}); |
|||
|
|||
export default Link; |
Loading…
Reference in new issue