I have a block of text that is coming from the database and it’s being mapped into a <p> element in react. During the mapping process that string is being run through a function that adds a strong tag around text if it matches what is input into a filter. For example if the string is “hello my name is fred” and the user inputs fred into the search, a <strong> tag will be wrapped around fred to make it stand out. What I’d like to do is add additional styles and not just use a strong tag but I can’t figure out how to do that w/ the restrictions of react. Here is my current code being used to dynamically add the strong tag →
inputText.forEach((item) => {
const substring = new RegExp(item, "gi");
result = result.replace(substring, (highlight) => `<strong>${highlight}</strong>`);
});
the issue is if I try to change the strong to a div and add either a style attribute or classname to it, it doesn’t seem to be rendered correctly by the dom using whatever styles I add. I’m not entirely sure how to solve this issue in react. Thanks!