Registry / web-framework / linkify-react

linkify-react

JSON →
library4.3.2jsnpmunverified

linkify-react is a React component that provides an interface to the underlying linkifyjs library, enabling the automatic detection and conversion of URLs, email addresses, and other specified patterns (such as hashtags via plugins) within text content into clickable HTML `<a>` elements. The current stable version is `4.3.2`. This package is actively maintained, with frequent patch and minor releases, often in close alignment with updates to the core `linkifyjs` library. A key differentiator is its seamless integration into React applications, allowing developers to declaratively render linkified text. It offers extensive customization options for link behavior, attributes, and rendered element types, abstracting away direct DOM manipulation. It serves as a user-friendly wrapper over `linkifyjs` to handle the complexities of parsing and rendering links within a React component tree.

npm install linkify-react
INSTALL
IMPORT
SIG · LINKIFY-REACT
L
linkify-react
web-frameworkjavascriptv4.3.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Linkify
import Linkify from 'linkify-react';
import { Linkify } from 'linkify-react'; // Linkify is a default export, not named. const Linkify = require('linkify-react').default;
The Linkify component is the default export. Use direct import for ESM or `require` for CJS environments.
LinkifyOptions
import type { LinkifyOptions } from 'linkifyjs';
import type { LinkifyOptions } from 'linkify-react';
Configuration options for Linkify are defined in the core `linkifyjs` package, not `linkify-react`.
Hashtag Plugin
import 'linkifyjs/plugins/hashtag';
import { hashtag } from 'linkifyjs/plugins/hashtag'; // Plugins are imported for their side effects, not as named exports.
Plugins like 'hashtag' or 'mention' extend `linkifyjs` functionality via side effects and must be imported directly from the `linkifyjs/plugins/` path. They don't expose named exports.

Demonstrates the basic usage of the Linkify component and advanced customization options. It shows how to apply custom attributes, format link text, provide custom React components for links, handle specific link types like hashtags, and validate links before rendering.

import React from 'react'; import Linkify from 'linkify-react'; import 'linkifyjs/plugins/hashtag'; // Optional: Import plugins for additional link types const LinkifyExample = () => { const textWithLinks = "Visit my website at example.com, email me at info@example.org, or check out #myproject on social media."; const customOptions = { // Customize attributes for all links attributes: { target: '_blank', rel: 'noopener noreferrer', className: 'my-custom-link' }, // Format the displayed text for URLs longer than 30 characters format: { url: (value: string) => value.length > 30 ? value.substring(0, 27) + '...' : value, }, // Provide a custom React component for all links component: ({ tagName, attributes, content }: any) => { const Tag = tagName; // 'a' return ( <Tag {...attributes} style={{ color: 'darkgreen', fontWeight: 'bold' }}> {content} </Tag> ); }, // Render specific link types differently (e.g., hashtags) render: { hashtag: ({ tagName, content, href }: any) => ( <a key={href} href={`https://twitter.com/hashtag/${content}`} style={{ color: 'purple' }}> #{content} </a> ) }, // Validate specific link types (e.g., only 'https' URLs) validate: { url: (value: string) => value.startsWith('https://') } }; return ( <div> <h1>Linkify React Usage Example</h1> <p>Original text: "{textWithLinks}"</p> <div style={{ border: '1px solid #eee', padding: '15px', backgroundColor: '#f9f9f9' }}> <h2>Default Linkify:</h2> <Linkify>{textWithLinks}</Linkify> </div> <div style={{ border: '1px solid #eee', padding: '15px', marginTop: '20px', backgroundColor: '#f9f9f9' }}> <h2>Linkify with Custom Options:</h2> <Linkify options={customOptions}>{textWithLinks}</Linkify> </div> </div> ); }; export default LinkifyExample;
Debug
Known issues
breakingVersion 4.1.0 dropped official support for Safari 10. Users targeting this browser version might encounter compatibility issues.
fix
Ensure target browsers are newer than Safari 10, or consider pinning to an older linkify-react version if Safari 10 support is critical.
affects: >=4.1.0
gotchaThe `linkifyjs` package is a peer dependency and must be installed separately alongside `linkify-react`. Failure to do so will result in runtime errors.
fix
Run `npm install linkifyjs linkify-react` or `yarn add linkifyjs linkify-react`.
affects: >=4.0.0
gotchaFor specific link types like hashtags or mentions to be recognized, their corresponding plugins from `linkifyjs/plugins/` must be explicitly imported, even if not directly used in code.
fix
Add `import 'linkifyjs/plugins/hashtag';` or similar imports at the top level of your application or component where `Linkify` is used.
affects: >=4.0.0
gotchaAs of v4.3.0, the package renamed its distribution files from `.cjs.js` and `.es.js` to `.cjs` and `.mjs`. While standard bundlers should handle this automatically, custom build configurations or direct imports by path might need adjustment.
fix
Verify that your bundler or module resolver correctly handles `.cjs` and `.mjs` extensions. For most users relying on `package.json`'s `main` and `module` fields, no action is needed.
affects: >=4.3.0
Errors
Common errors & fixes
Error: Can't resolve 'linkifyjs' in 'your-project/node_modules/linkify-react'
The peer dependency `linkifyjs` is not installed in your project.
fix
Install `linkifyjs` as a direct dependency: `npm install linkifyjs` or `yarn add linkifyjs`.
TypeError: Linkify is not a function (or) TypeError: Cannot read properties of undefined (reading 'default')
Incorrect import statement for the `Linkify` component, often trying to named import a default export or using CommonJS `require` incorrectly with an ESM default export.
fix
Use `import Linkify from 'linkify-react';` for ESM or `const Linkify = require('linkify-react');` for CommonJS (as it's a default export that works well with CJS interop).
Hashtags are not being detected or converted into links.
The `hashtag` plugin for `linkifyjs` has not been imported.
fix
Add `import 'linkifyjs/plugins/hashtag';` to your application's entry file or the component file where `Linkify` is used.
Upgrade
Version history
4.3.2latest on npm
Audit
Dependencies
linkifyjsrequiredCore link detection logic; required peer dependency.
reactrequiredRequired for React component functionality.
Agent activity
2 hits · last 30 days
node
2
Resources
linkify-react — npm install linkify-react · libregistry