最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Render dynamic html in react js - Stack Overflow

programmeradmin2浏览0评论

I want to render a dynamic html text provide by a API in react js but I don't know how to do.

for example :

   dynamicHtml= <div> hello <span color=red> StackOverFlow </span> </div>

   render() {

        return (
            <div>  {dynamicHtml} </div>
        );
   }

I want to dysplay only Hello StackOverFlow with the red color on StackOverFlow

I want to render a dynamic html text provide by a API in react js but I don't know how to do.

for example :

   dynamicHtml= <div> hello <span color=red> StackOverFlow </span> </div>

   render() {

        return (
            <div>  {dynamicHtml} </div>
        );
   }

I want to dysplay only Hello StackOverFlow with the red color on StackOverFlow

Share Improve this question asked Dec 17, 2017 at 19:27 Arnold MappsArnold Mapps 2101 gold badge4 silver badges11 bronze badges 3
  • I don't really understand what you're asking, what the question is, etc – Matt Fletcher Commented Dec 17, 2017 at 19:42
  • I want to dysplay a dynamic html provided by a API. – Arnold Mapps Commented Dec 17, 2017 at 20:54
  • 1 ... repeating what you say in your question is not the same as expanding on it. – Matt Fletcher Commented Dec 17, 2017 at 21:01
Add a ment  | 

1 Answer 1

Reset to default 6

use dangerouslySetInnerHTML

     function createMarkup(text) { return {__html: text}; };
     <render() {

            return (
               <div dangerouslySetInnerHTML={createMarkup()} />
            );
       }
发布评论

评论列表(0)

  1. 暂无评论