2

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

3
  • I don't really understand what you're asking, what the question is, etc Commented Dec 17, 2017 at 19:42
  • I want to dysplay a dynamic html provided by a API. Commented Dec 17, 2017 at 20:54
  • 1
    ... repeating what you say in your question is not the same as expanding on it. Commented Dec 17, 2017 at 21:01

1 Answer 1

6

use dangerouslySetInnerHTML

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

            return (
               <div dangerouslySetInnerHTML={createMarkup()} />
            );
       }
Sign up to request clarification or add additional context in comments.

2 Comments

Lol. I get the feeling that they advise against that... ;)
Lol. Wish they could have another solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.