Files
factorio-clusterio/packages/web_ui/src/components/Link.tsx
T
Danielv123 8879f8dd80 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
2024-02-09 09:11:53 +03:00

48 lines
893 B
TypeScript

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;