linkifyjs
linkifyjs copied to clipboard
How to use mention with linkify-react?
import Linkify from "linkify-react";
import mention from "linkifyjs/plugins/mention"
const linkifyOptions = {
format: function (value, type) {
if (type === "url") {
let re1 = /http(s)?:\/\//;
value = value.replace(re1, "");
if (value.length > 50) value = value.slice(0, 50) + "…";
}
if (type === "mention" && value.length > 10) {
value = value.slice(0, 20) + "…";
}
return value;
},
tagName: {
mention: () => Link,
},
formatHref: {
mention: (href) => {},
},
attributes: (href, type) => {
if (type === "mention") {
return {
to: "/profile" + href,
};
}
return {};
},
target: {
url: "_blank",
},
}
<Linkify options={linkifyOptions}>{text}</Linkify>
package.json
"linkify-plugin-mention": "^3.0.0",
"linkify-react": "^3.0.0",
"linkifyjs": "^3.0.0"
This used to work normally,I was little confused.