Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
itkach opened this issue Nov 1, 2019 · 6 comments
Open

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

itkach opened this issue Nov 1, 2019 · 6 comments

Comments

@itkach
Copy link

itkach commented Nov 1, 2019

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

@theycallmejpo
Copy link

Facing same issue

@Gr8z
Copy link

Gr8z commented Sep 20, 2020

You need to import it like so:

import Linkify from 'react-linkify'

@vractal
Copy link

vractal commented Oct 7, 2020

@Gr8z this is not the same thing

@teddybee
Copy link

teddybee commented Apr 11, 2021

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.

FluorescentHallucinogen added a commit to FluorescentHallucinogen/react-linkify that referenced this issue Apr 29, 2021
@FluorescentHallucinogen

See #108. 😉

@shihanng
Copy link

Adding on top of what @teddybee mentioned above, linkify is used in the match decorator:

import LinkifyIt from 'linkify-it';
import tlds from 'tlds';
const linkify = new LinkifyIt();
linkify.tlds(tlds);
export default (text: string): Array<Object> => {
return linkify.match(text);
};

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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants