How to convert it to html element?
P粉248602298
P粉248602298 2023-09-08 21:58:04
0
1
517

I'm trying to create a function that highlights words in a sentence. Here is the corresponding code.

highlightText = () => { const { questionItem, } = this.props; const words = questionItem.split(/\s+/); const highlighted = words.map((word, index) => ( {word} )); const text = highlighted.join(' '); console.log(text); console.log({ highlighted }); return highlighted; }

Here, if I console "text", I get [Object object], so I return "highlight" and then use reduce to join it.

const text3 = 

{this.highlightText().reduce((prev, curr) => [prev, ' ', curr])}

;

I want to use this "text3" in the component. The problem is that I get "text3" as

I want it to be an HTML element so I can use it in my component. How can I convert it? Also, if I display

{this.highlightText().reduce((prev, curr) => [prev, ' ', curr])}

directly in the web page instead of Using it in my component works fine.

P粉248602298
P粉248602298

reply all (1)
P粉211600174

Just create a new component withprops. Try this...

export default function HighlightText({text}) { return {text}
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!