0

I am working on some kind of store and i am using dangerouslysetinnerhtml in my code but i have been asked not to use it and also not to use third party libraries. Is there a better alternative i can use? this is the code below:

            <div
              className="product-description"
              dangerouslySetInnerHTML={{
                __html: purify(this.props.product.description),
              }}
            />
El Rey
  • 9
  • 4
  • Probably you should keep it: https://stackoverflow.com/a/37339542/7916438 – tevemadar Oct 03 '22 at 10:25
  • i wish i could. but i am not allowed to use it – El Rey Oct 03 '22 at 10:38
  • If you want a little coding challenge, you can build a custom component that parses HTML strings and returns react components in a recursive way. So you would need a parsing function that returns the tree structure of the HTML string and then create the corresponding HTML element (with the attributes) for each of the tree nodes. Would be a nice challenge for a second semester computer science lecture :D – Fatorice Oct 03 '22 at 11:50

0 Answers0