admin管理员组

文章数量:1316974

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()} />
            );
       }

本文标签: javascriptRender dynamic html in react jsStack Overflow