简体   繁体   中英

how to use dangerouslySetInnerHTML in react-highlight-words

I want to use dangerouslySetInnerHTML in react-highlight-words package in Highlighter tag.

          <Highlighter
            activeClassName=""
            activeIndex=...
            highlightClassName=...
            highlightStyle=...
            searchWords={srchArr}
            autoEscape=...
            textToHighlight={{ __html: string}}
          />

textToHighlight is giving me [Object Object] in result. How i solve it? Please help!

You are getting [Object Object] because of this line,

 textToHighlight={{ __html: string}}

Here string might be an Object , you should use this,

 textToHighlight={{ __html: JSON.stringify(string)}}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM