This is how I'm trying to replace some strings with elements inside the render()-method of my component. But this fails, as I'm getting the replaced string as a real string instead of an elements.
What do I have to do, to get Link as a rendered Link-element? Right now it is just a string output.
And is this the correct 'react'-way to do that?
return (
<List>
{
elements.map(e => {
return (
<List.Item>
{
links ? links.map(link => {
return e.content.replace(
new RegExp(link.label, 'gi'),
'<Link to="/' + link.id + '">$&</Link> (<Icon name="external" />)'
)
}) : ''
}
</List.Item>
)
})
}
</List>
)
elements
[{
"_id" : "zQS6pXicvXk7K2rZ4",
"content" : "This is a sample text to add some links",
"links" : [
{
"id" : "Dn59y87PGhkJXpaiZ",
"type" : "articles",
"label" : "Sample"
},
{
"id" : "GhkJXpaiZDn59y87P",
"type" : "articles",
"label" : "add"
},
{
"id" : "XpaiZDn5GhkJ9y87P",
"type" : "articles",
"label" : "External"
}
]
}]
elementstypically look like? Andlinks?contentinto an array of strings, like["This is a", "sample", "text to", "add", "some links"]according to thelabels, then replace the array elements with<Link />s.