forked from clusterio/clusterio
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaced react Link with custom component
The custom component merges the behaviour of antd Typography.Link and the react-router.dom Link after the custom component prop was removed in v6 according to this guide: https://reactrouter.com/en/main/upgrading/v5#remove-link-component-prop
- Loading branch information
1 parent
89919f7
commit 8879f8d
Showing
5 changed files
with
60 additions
and
11 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React from "react"; | ||
import { Typography } from "antd"; | ||
import { | ||
LinkProps, | ||
useHref, | ||
useLinkClickHandler, | ||
} from "react-router-dom"; | ||
import { BaseType } from "antd/es/typography/Base"; | ||
|
||
const Link = React.forwardRef( | ||
( | ||
{ | ||
onClick, | ||
replace = false, | ||
state, | ||
target, | ||
to, | ||
type, | ||
...rest | ||
}: LinkProps, | ||
ref | ||
) => { | ||
let href = useHref(to); | ||
let handleClick = useLinkClickHandler(to, { | ||
replace, | ||
state, | ||
target, | ||
}) as (event: React.MouseEvent<HTMLElement, MouseEvent>) => void; | ||
|
||
return ( | ||
<Typography.Link | ||
{...rest} | ||
href={href} | ||
onClick={(event) => { | ||
onClick?.(event as React.MouseEvent<HTMLAnchorElement, MouseEvent>); | ||
if (!event.defaultPrevented) { | ||
handleClick(event); | ||
} | ||
}} | ||
ref={ref as React.RefObject<HTMLElement> | null} | ||
target={target} | ||
type={type as BaseType} | ||
/> | ||
); | ||
} | ||
); | ||
export default 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
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