try it:

const PolicyHTML = require('./Policy.html');

<WebView
  source={PolicyHTML}
  style={{flex: 1}}
 />
Answer from Fmussap on Stack Overflow
🌐
npm
npmjs.com › package › react-native-render-html
react-native-render-html - npm
January 24, 2022 - ... import React from 'react'; import { useWindowDimensions } from 'react-native'; import RenderHtml from 'react-native-render-html'; const source = { html: ` <p style='text-align:center;'> Hello World!
      » npm install react-native-render-html
    
Published   Jan 24, 2022
Version   6.3.4
Discussions

reactjs - how to import HTML file into React component and use it as a component? - Stack Overflow
I want to import an HTML file into a React component peft.html Page Title More on stackoverflow.com
🌐 stackoverflow.com
How to Load local HTML and local js in react-native-webview in IOS?
For me, this was easy to do with the core RN webview, but it failed once I switched to the react-native-webview community package. This is how I fixed it . I'm using this in a production app now and it's working fine (although I should note I inline all the JS in the html file I'm importing - you may want to do the same. I use HtmlWebpackInlineSourcePlugin in webpack to do that). More on reddit.com
🌐 r/reactnative
15
3
September 3, 2019
Render local html file in React Native - Stack Overflow
I run React Native using Expo for android and I'm trying to render html file (it shows a map image) in local directory, but it doesn't work properly. I followed several references, installed webview dependencies in expo and npm both. The problem is that the result is just html code view, not a map image ... import ... More on stackoverflow.com
🌐 stackoverflow.com
react native webview load from device local file system - Stack Overflow
I'm trying to load .html, .js, .css files from device's local file system into React Native WebView component. I was able to get the path to the index.html file but specifying this as the url for the More on stackoverflow.com
🌐 stackoverflow.com
🌐
Medium
medium.com › yonder-techblog › react-native-offline-content-display-with-local-html-files-in-webview-7d22a0cf46fb
React Native: Offline Content Display with Local HTML Files in WebView | by Alex-Stefan Albu | Yonder TechBlog | Medium
February 21, 2024 - To display HTML files in a React Native app using a WebView component, you first need to import the WebView from the ‘react-native-webview’ library. Then, you can use the WebView component in your JSX/TSX code and specify the source of the HTML file using the ‘source’ prop.
🌐
About React
aboutreact.com › home › load local html file or url in react native using react-native-webview
Load Local HTML File or URL in React Native using react-native-webview
December 3, 2022 - –save is optional, it is just to update the dependency in your package.json file. After the updation of React Native 0.60, they have introduced autolinking so we do not require to link the library but need to install pods. So to install pods use ... If you want to load the HTML from the local HTML file into the WebView then you need to put them in the below-described directory.
🌐
Reddit
reddit.com › r/reactnative › how to load local html and local js in react-native-webview in ios?
r/reactnative on Reddit: How to Load local HTML and local js in react-native-webview in IOS?
September 3, 2019 -

I am trying to load a charting library in webview. I have tried many answers on StackOverflow and GitHub but I was only able to display it correctly on Android using {uri: 'file:///android_asset/www/index.html'} but on iOS when I do import HTML_FILE from "./resources/index.html"; ORconst HTML = require('./resources/index.html'); it doesn't work.

The app shows a blank screen, and the metro bundler throws resources/highcharts/highcharts.js' cannot be loaded as its extension is not registered in assetExts.

PS:I followed similar approach for iOS : https://aboutreact.com/load-local-html-file-url-using-react-native-webview/

I have added simmilar question on StackOverflow as well : https://stackoverflow.com/questions/57726507/add-local-html-and-js-file-using-react-native-webview

PPS :"react-native": "0.60.5","react-native-webview": "^7.0.1"
I do not use EXPO

Top answer
1 of 5
16

In react native it is now possible to require an HTML file and use it as the source for the web view like this (the path is relative to the react-native file you use it in):

const webapp = require('./webapp/index.html');

and the use it in the WebView like this:

<WebView source={webapp} />

Unfortunately this does not load CSS and JavaScript files, that are referenced in the HTML. A solution could be, to write all the CSS and JS inline (e.g. by using a build process).

2 of 5
9

I was able to include html5/javascript into project by using { html: , baseUrl: } as source. But to be frank, it's more like a lucky shot.

<WebView source={{ html: HTML, baseUrl: 'web/' }} />

I have index.html, which require pano2vr_player.js and pano.xml to make this code work.

const HTML = `
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<title></title>
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0" />
		<meta name="apple-mobile-web-app-capable" content="yes" />
		<meta name="apple-mobile-web-app-status-bar-style" content="black" />
		<meta name="mobile-web-app-capable" content="yes" />
		<style type="text/css" title="Default">
			body, div, h1, h2, h3, span, p {
				font-family: Verdana,Arial,Helvetica,sans-serif;
			}
    </style>
	</head>
	<body>
		<script type="text/javascript" src="pano2vr_player.js">
		</script>
		<div id="container" style="width:100%;height:100%;">
		<br>Loading...<br><br>
		This content requires HTML5 with CSS3 3D Transforms or WebGL.
    </div>
		<script type="text/javascript">
			// create the panorama player with the container
			pano=new pano2vrPlayer("container");
		  window.addEventListener("load", function() {
			  pano.readConfigUrlAsync("pano.xml");
		  });
		</script>
	</body>
</html>`;

class PanoView extends Component {

  render() {
    return (
      <View>
        <WebView
          style={{ flex: 1, width: 1024, height: 768 }}
          source={{ html: HTML, baseUrl: 'web/' }}
          javaScriptEnabledAndroid={true} />
      </View>
    );
  }
}

And finally add files/folder ('/web' same as baseUrl) to XCode project

And it works! But I'm not sure how...

Find elsewhere
🌐
GitHub
github.com › react-native-webview › react-native-webview › issues › 392
Load local html file · Issue #392 · react-native-webview/react-native-webview
March 6, 2019 - react-native-webview / react-native-webview Public · Notifications · You must be signed in to change notification settings · Fork 3.1k · Star 7k · New issueCopy link · New issueCopy link · Closed · Closed · Load local html file#392 · Copy link · Labels ·
Author   react-native-webview
🌐
LogRocket
blog.logrocket.com › home › how to render html to react native
How to render HTML to React Native - LogRocket Blog
June 4, 2024 - Apart from the react-native-render-html library, there’s one more option for rendering web components into React Native applications — React Native WebView. This modern cross-platform alternative to the built-in webview has great support for embedding anything from whole web apps to simple HTML files. In this library, you can find a similar pattern as above. Check out the below example: //Javascript - JSX import React, { Component } from 'react'; import { StyleSheet, Text, View } from 'react-native'; import { WebView } from 'react-native-webview'; // ...
🌐
Scaler
scaler.com › home › topics › react native render html
React Native Render HTML - Scaler Topics
July 6, 2023 - After installing the library, you can import the necessary components from react-native-render-html and use them in your code. The main component is HTML, which accepts the HTML content as a prop and renders it within your app.
🌐
Medium
medium.com › @nutanbhogendrasharma › how-to-display-html-content-in-react-native-mobile-app-b43cfda8325
How to Display HTML Content in React Native Mobile App | by Nutan | Medium
September 7, 2021 - Create Native Apps for Android and iOS using React Native · import React from 'react'; import { Text, View } from 'react-native';const Main = () => { return( <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}> <Text>Hello ...
🌐
GitHub
github.com › react-native-webview › react-native-webview › blob › master › docs › Guide.md
react-native-webview/docs/Guide.md at master · react-native-webview/react-native-webview
To do this on iOS and Windows, ... as shown below. import React, { Component } from 'react'; import { WebView } from 'react-native-webview'; const myHtmlFile = require('./my-asset-folder/local-site.html'); class MyWeb extends ...
Author   react-native-webview
🌐
React Native
reactnative.dev › docs › intro-react
React Fundamentals · React Native
2 weeks ago - Here is how you do it: To define your Cat component, first use JavaScript’s import to import React Native’s Text Core Component:
🌐
GitHub
github.com › react-native-webview › react-native-webview › issues › 746
No way to load a local HTML file in the webview on Android · Issue #746 · react-native-webview/react-native-webview
July 28, 2019 - const myHtml = require("./index.html"); // In Render <WebView ref={this._webViewRef} source={myHtml} /> It worked perfectly fine. However on Android it threw TypeError: Cannot use 'in' operator to search for 'method' So, I tried manually resolving the asset uri like I used to do for Images, <WebView ref={this._webViewRef} source={{uri: Image.resolveAssetSource(myHtml).uri}} /> However it directly loads the file HTML source instead of the actual webpage.
Author   react-native-webview
🌐
GitHub
github.com › react-native-community › react-native-webview › issues › 630
WebView does not load local HTML file · Issue #630 · react-native-webview/react-native-webview
June 11, 2019 - This is the error ERR_ACCESS_DENIED ... @flow */ import React, {Component} from 'react'; import { StyleSheet, Text, View, Button,Platform } from "react-native"; import { WebView } from 'react-native-webview'; import HTML_FILE from "./AdListing/index.html" const isAndroid= ...
Author   react-native-webview
🌐
Medium
medium.com › @snehabagri.90 › reactnative-webview-with-local-content-c98a09340801
ReactNative: WebView with local content | by Sneha Bagri | Medium
February 13, 2018 - We need to add the dependencies of widget along with the html in the native resource directory for both android and ios as explained below:- ... Create assets folder by clicking on File->New->Folder-> Assets folder on android studio. Add the widget to the assets folder as seen below: 3. The code for the External Widget will be as below: import React, { Component } from 'react' import {WebView} from 'react-native'class ExternalWidget extends Component { render() { <WebView source={{uri:'file:///android_asset/widget/index.html'}} scalesPageToFit/> } }export default ExternalWidget