Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

react-external-link

acelaya4kMIT2.5.0TypeScript support: included

Build Status [![Code Coverage](https://img.sh

react, link, external, target, noopener, noreferrer

readme

React External Link

Build Status Code Coverage npm npm downloads GitHub license Paypal Donate

This library provides a simple ExternalLink component for react which can be used to render a tags with both target="_blank" and rel="noopener noreferrer" attributes.

Installation

npm install react-external-link --save

Usage

If you just need a simple link with no custom text:

import { ExternalLink } from 'react-external-link';

const MyComponent = () => (
  <div>
    <ExternalLink href="https://example.com" />
  </div>
);

export default MyComponent;

This will be rendered as:

<a href="https://example.com" target="_blank" rel="noopener noreferrer">https://example.com</a>

If you need to provide a custom content, you can do so by providing the ExternalLink's children:

import { ExternalLink } from 'react-external-link';

const MyComponent = () => (
  <div>
    <ExternalLink href="https://example.com">
      <span>Visit the site</span>
    </ExternalLink>
  </div>
);

export default MyComponent;

This will be rendered as:

<a href="https://example.com" target="_blank" rel="noopener noreferrer">
  <span>Visit the site</span>
</a>

It is also possible to pass any extra props, and they will be propagated to the link:

import { ExternalLink } from 'react-external-link';

const MyComponent = () => <ExternalLink href="https://example.com" className="my-class" />;

export default MyComponent;

The result in this case will be:

<a href="https://example.com" target="_blank" rel="noopener noreferrer" class="my-class">https://example.com</a>

changelog

CHANGELOG

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

[2.5.0] - 2025-03-29

Added

  • Nothing

Changed

  • Start publishing package as ESM only.

Deprecated

  • Nothing

Removed

  • Nothing

Fixed

  • Nothing

[2.4.0] - 2024-12-06

Added

  • Add support for React 19

Changed

  • Update to @shlinkio/eslint-config-js-coding-standard 3.0, and migrate to ESLint flat config.

Deprecated

  • Nothing

Removed

  • Drop support for React 17

Fixed

  • Nothing

[2.3.1] - 2024-04-09

Added

  • Nothing

Changed

  • Nothing

Deprecated

  • Nothing

Removed

  • Nothing

Fixed

  • Fix incorrect publishing

[2.3.0] - 2024-04-08

Added

  • Nothing

Changed

  • Update dependencies.
  • Update coding standard.
  • Migrate to shlink reusable workflows.

Deprecated

  • Nothing

Removed

  • Remove version field from package.json

Fixed

  • Nothing

[2.2.0] - 2023-04-20

Added

  • Nothing

Changed

  • #44 Migrate to vite for bundling.
  • #45 Migrate to vitest for testing.

Deprecated

  • Nothing

Removed

  • Nothing

Fixed

  • Nothing

[2.1.0] - 2023-02-19

Added

  • Nothing

Changed

  • Update dependencies

Deprecated

  • Nothing

Removed

  • Nothing

Fixed

  • Nothing

[2.0.1] - 2023-01-03

Added

  • Nothing

Changed

  • Nothing

Deprecated

  • Nothing

Removed

  • Nothing

Fixed

  • Ensured provided rel attribute does not overwrite noopener noreferrer, but it's appended instead.

[2.0.0] - 2022-05-12

Added

  • Nothing

Changed

  • ExternalLink props now extend AnchorHTMLAttributes<Element>.
  • Updated dependencies, including Jest 28.

Deprecated

  • Nothing

Removed

  • Nothing

Fixed

  • Nothing

[1.3.0] - 2022-04-02

Added

  • Added support for React 18

Changed

  • Updated to shlink coding standard 2.0

Deprecated

  • Nothing

Removed

  • Nothing

Fixed

  • Nothing

[1.2.2] - 2021-07-07

Added

  • Nothing

Changed

  • Nothing

Deprecated

  • Nothing

Removed

  • Nothing

Fixed

  • #30 Fixed wrong generation of definition types before publishing.

[1.2.1] - 2021-03-05

Added

  • Nothing

Changed

  • Nothing

Deprecated

  • Nothing

Removed

  • Nothing

Fixed

  • #21 Fixed linting by updating to @shlinkio/eslint-config-js-coding-standard as the coding style.

[1.2.0] - 2020-12-19

Added

  • Nothing

Changed

  • #16 Migrated build to Github Actions.
  • #17 Migrated release publishing to Github Actions.
  • #18 Migrated to Codecov as coverage backend.
  • #19 Updated dependencies.

Deprecated

  • Nothing

Removed

  • Nothing

Fixed

  • Nothing

[1.1.0] - 2019-09-03

Added

  • #2 Added travis config and enabled project builds.
  • #1 Added tests which are run as part of the build.
  • #5 Project added to scrutinizer.
  • #3 Automated package releases.

Changed

  • #6 Changed coding styles to adidas coding styles.

Deprecated

  • Nothing

Removed

  • Nothing

Fixed

  • Nothing

[1.0.1] - 2019-08-29

Added

  • Nothing

Changed

  • Nothing

Deprecated

  • Nothing

Removed

  • Nothing

Fixed

  • Fixed typescript interface not accepting any extra props in ExternalLink

[1.0.0] - 2019-08-28

Added

  • First stable release

Changed

  • Nothing

Deprecated

  • Nothing

Removed

  • Nothing

Fixed

  • Nothing