While creating custom autocomplete component I stuck with this problem: I got a string and substring(first part of the string, the one that user enters in autocompete field), and I need to show that part in bold in results list.
But I cannot use str.replace
like
var re = new RegExp(find, 'g');
return str.replace(re, '<b>'+find+'</b>');
because it will return string and I need JSX.
So basically the problem is - I have JSX and I need to make some part of it in bold. I need a function that takes JSX and like inject <b>
tag in it in special places
This is what I got so far
boldJSX(str, find){
if(!find) return str;
return <span><b>{find}</b>{str.slice(find.length)}</span>
}