I am using React and I try to highlight the value typed by the user in a string containing this value.
In order to highlight this value, I am trying to replace the substring corresponding to this.props.value
with a substring containing this value + html.
For example, for the item.name
: John
If the user types "Jo". I want to display John
The substring "Jo" is highlighted.
This is my code:
{this.props.value.length > 0 &&
item.name.search(this.props.value)
? item.name.replace(this.props.value, `<span className="myClass">${this.props.value}</span>`)
: item.name
}
The value returned is plain text, the span is not taken as html. How can I make this html tags interpreted?