LoginSignup
14
9

More than 5 years have passed since last update.

ReactでHTML文字列をDOM要素として描画するコンポーネント

Last updated at Posted at 2017-02-14

render内からpropsにhtmlの文字列を指定すると、DOM要素に変換してくれるReactコンポーネント。
dangerouslySetInnerHTMLを使用すれば、html文字列をDOM要素に変換してくれる。

const HTMLComponent = (props) => {
    return(
        <span dangerouslySetInnerHTML={{__html: props.htmlstring}}></span>
    );
}
14
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
9