React - How to pass HTML tags in props?

前端 未结 20 1285
甜味超标
甜味超标 2020-12-07 11:58

I want to be able to pass text with HTML tags, like so:

not working.\" />

Bu

20条回答
  •  攒了一身酷
    2020-12-07 12:36

    You can use dangerouslySetInnerHTML

    Just send the html as a normal string

    
    

    And render in in the JSX code like this:

    Just be careful if you are rendering data entered by the user. You can be victim of a XSS attack

    Here's the documentation: https://facebook.github.io/react/tips/dangerously-set-inner-html.html

提交回复
热议问题