Answer the question
In order to leave comments, you need to log in
How to correctly insert an html tag into a string so that it is rendered as a dom element?
Hello!
You need to find a link in a line of text and make it clickable, that is, in fact, cut out the text of the link and replace it with a tag
wrote such a function<a href='ссылка'>ссылка</a>
getTitle(title = 'Подробнее по ссылке: https://yandex.ru бла бла') {
const regExp = /[[email protected]:%_\+.~#?&\/=]{2,256}\.[a-z]{2,4}\b(\/[[email protected]:%_\+.~#?&\/=]*)?/;
if (title.match(regExp)) {
const url = title.match(regExp)[0];
const link = <a href={url}>{url}</a>;
return title.replace(url, link);
} else return title;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question