revite/src/lib/ConditionalLink.tsx

17 lines
377 B
TypeScript
Raw Normal View History

import { Link, LinkProps } from "react-router-dom";
2021-07-05 06:23:23 -04:00
type Props = LinkProps &
2021-07-05 06:25:20 -04:00
JSX.HTMLAttributes<HTMLAnchorElement> & {
active: boolean;
};
export default function ConditionalLink(props: Props) {
2021-07-05 06:25:20 -04:00
const { active, ...linkProps } = props;
2021-07-05 06:25:20 -04:00
if (active) {
return <a>{props.children}</a>;
} else {
return <Link {...linkProps} />;
}
}