I am building a search component, and for each possible auto suggestion, I'd like to highlight where the searched term appears.
I've found this and I've been trying to use regex to achieve my desired result, but I think something in the way components works prevent it from working, and I can't figure out how to get it to work.
Here's what I am trying to do:
var reg = new RegExp(searchTerm, "gi");
return (
<div className="single-result">
{result.name.replace(reg, searchTerm => {
return <div className="single-result__bold"> {searchTerm}</div>;
})}
</div>
);
But what I get printed looks like this:
[object Object]A[object Object]d[object Object]a[object Object]l[object Object]i[object Object]n[object Object]e[object Object] [object Object]A[object Object]r[object Object]r[object Object]a[object Object]u[object Object]l[object Object]t[object Object]