Vinay Sharma
Vinay Sharma

Reputation: 3777

React Native: Render HTML in View

I have a React Native app which is receiving an HTML file from the backend. This is the content of the HTML file:

<html>
  <head>
    <style>
      #wrapper {
        // styling
      }
      .child {
        // styling
      }
      #img {
        // styling
      }
      #desc {
        // styling
      }
    </style>
  </head>

  <body>
    <div id="wrapper">
      <div id="img" class="child"></div>
      <div id="desc" class="child"></div>
    </div>
  </body>

  <script>
    const img = document.getElementById("img");

    img.addEventListener("click", () => {
      // logic
    });
  </script>
</html>

I just want to display this HTML in a react-native view along with both it's style as well script tag.

Upvotes: 0

Views: 3587

Answers (2)

Akram
Akram

Reputation: 97

I used React-native-render-html library to render html and it works great versatile and very easy to use, you can het it from

https://www.npmjs.com/package/react-native-render-html

Upvotes: 0

Noman Gul
Noman Gul

Reputation: 397

you should use some sort of prebuilt library for that...

here's the one I found really useful => https://github.com/archriss/react-native-render-html

Upvotes: 1

Related Questions