react-linkify
react-linkify copied to clipboard
import { linkify } from "react-linkify" gives undefined
In 0.2.2 import { linkify } from "react-linkify" resulted in linkify referencing global LinkifyIt instance. In 1.0.0-alpha linkify is undefined
Facing same issue
You need to import it like so:
import Linkify from 'react-linkify'
@Gr8z this is not the same thing
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.
See #108. :wink:
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>