This is an example of creating links in a string using react. Most of the examples I found were my manipulating dom so after so messing around I figured out how to do it.
function profile() {
const hashtagRegex = /\B(\#[a-zA-Z]+\b)(?!;)/gm;
const { fullName, userName, image, bio } = userProfileData;
const bioMatch = bio && bio.match(hashtagRegex);
const editbio = bio && bio.split(" ");
bioMatch &&
editbio.map((word, index) => {
if (word.match(hashtagRegex)) {
editbio[index - 1] = editbio[index - 1] + " ";
editbio[index] = <a href="https://google.com">{word}</a>;
} else {
editbio[index] = " " + word;
}
});
return (
<div className="profile">{editbio}</div>
);
}
If you add spacing directly to the array index it converts the link into [object][object] and if you try to join in the return it does the same so this worked for me. If someone has a better way to do it, please share.
The easiest way to link the website to the text if you are trying to do it with HTML would be
<p><a href="link">word</a></p>