html react parser throws an issue

708 Views Asked by At

I am trying to render html content via html-react-parser in react. But I will get following error in the console.

Warning: validateDOMNesting(...): <html> cannot appear as a child of <div>.

My html input to the parse method is as follows.

<!DOCTYPE html>
<html>
 <head>
  <style>
   body {
     background-color: lightblue;
   }

   h1 {
    color: white;
    text-align: center;
   }

   p {
     font-family: verdana;
     font-size: 20px;
   }
 </style>
</head>
<body>

 <h1>My First CSS Example</h1>
 <p>This is a paragraph.</p>

</body>
</html>

So I know the reason for the issue was my inner html contains inside of html tag. But I don't need to remove it because that input is coming from backend and I need to render as it is via the parser. Is there any way get rid from this console log error?

1

There are 1 best solutions below

1
On

You are trying to insert html as a child of div that's why you get this. Try using only the code you need:

<h1>My First CSS Example</h1>
<p>This is a paragraph.</p>