react-linkify icon indicating copy to clipboard operation
react-linkify copied to clipboard

import { linkify } from "react-linkify" gives undefined

Open itkach opened this issue 5 years ago • 6 comments

In 0.2.2 import { linkify } from "react-linkify" resulted in linkify referencing global LinkifyIt instance. In 1.0.0-alpha linkify is undefined

itkach avatar Nov 01 '19 13:11 itkach

Facing same issue

theycallmejpo avatar May 13 '20 08:05 theycallmejpo

You need to import it like so:

import Linkify from 'react-linkify'

Gr8z avatar Sep 20 '20 13:09 Gr8z

@Gr8z this is not the same thing

vractal avatar Oct 07 '20 00:10 vractal

The typedef declaration is missing for that export, and it is using linkify-it package. If you want to customize something, probably should use the componentDecorator property and look at the package's defaultComponentDecorator.js.

teddybee avatar Apr 11 '21 15:04 teddybee

See #108. :wink:

FluorescentHallucinogen avatar Apr 29 '21 16:04 FluorescentHallucinogen

Adding on top of what @teddybee mentioned above, linkify is used in the match decorator: https://github.com/tasti/react-linkify/blob/325cb5e43300d7ada5bdf8d2849783d98fcd3c2c/src/decorators/defaultMatchDecorator.js#L3-L11

Therefore if we want to use a customized version of linkify, we can create a custom match decorator with a new LinkifyIt instance,

import Linkify from "react-linkify";
import LinkifyIt, { Match } from "linkify-it";

const linkify = new LinkifyIt();
linkify.tlds(tlds);
linkify.add("@", {
  // Add custom feature here
});

const matchDecorator = (text: string): Match[] | null => {
  return linkify.match(text);
};

and use Linkify component with the decorator:

        <Linkify
          matchDecorator={matchDecorator}
        >
          ...
        </Linkify>

shihanng avatar Nov 23 '21 08:11 shihanng