简体   繁体   中英

Sending HTML tags in props - react

I need something function or trick to allow using HTML tags in react's props, because i'm using ckeditor for form.

my code:

render(){
    let name = this.props.name;
    let text = this.props.description;
    console.log(text);
    return (
        <li class="collection-item avatar">
          <span class="title"> <strong> {name} </strong> </span>
          <p > {text} </p>
          <a href="#!" class="secondary-content"><i class="material-icons">grade</i></a>
        </li>
      )
  }
}

dangerouslySetInnerHTML might help you.

Example from doc:

function createMarkup() { return {__html: 'First &middot; Second'}; };
<div dangerouslySetInnerHTML={createMarkup()} />

Always keep in mind that setting html directly can lead to XSS, so you should avoid the stuff as long as possible.

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