React - How to pass HTML tags in props?

前端 未结 20 1337
甜味超标
甜味超标 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:38

    You can use mixed arrays with strings and JSX elements (see the docs here):

    not,  "working."]} />
    

    There's a fiddle here that shows it working: http://jsfiddle.net/7s7dee6L/

    Also, as a last resort, you always have the ability to insert raw HTML but be careful because that can open you up to a cross-site scripting (XSS) attack if aren't sanitizing the property values.

提交回复
热议问题