externalLink.tsx 496 B

123456789101112131415161718
  1. import * as React from 'react';
  2. type AnchorProps = React.HTMLProps<HTMLAnchorElement>;
  3. type Props = {
  4. className?: string;
  5. openInNewTab?: boolean;
  6. } & Omit<AnchorProps, 'target'>;
  7. const ExternalLink = React.forwardRef<HTMLAnchorElement, Props>(function ExternalLink(
  8. {openInNewTab = true, ...props},
  9. ref
  10. ) {
  11. const anchorProps = openInNewTab ? {target: '_blank', rel: 'noreferrer noopener'} : {};
  12. return <a ref={ref} {...anchorProps} {...props} />;
  13. });
  14. export default ExternalLink;