After sending a to an API with a ‘search value’ that searches the database for the value and respond with data containing the value. I want to highlight the given word or search value in the response. The respond is populated to the UI
<center>
{Object.keys(Disp).map((key, i) => (
<center key={i} className="PublicationCard">
<span> {key}</span>
<a href={"https://www." + Disp[key]}> View Publication</a>
</center>
))}
</center>
The Key is a sentence but I want to bolden a word in the key
For example, let say the key is "Discussions about Supervised Artificial Intelligence" and the search query was artificial intelligence, all I want to do is to bold the search query that is "artificial intelligence’ in the UI
2
Answers
Maybe you can create a function to generate multiple span tags.
And use in your code :
And then add style for class "highlight
So Finally :
The example with
RegExp
works faster, but here is a simpler way.And use it like: