Including Local HTML File in Webview Component

#1

I’m trying to build a component that contains a local HTML file inside a react-native webview component. Given the particulars of how expo projects are set up, where should I put the HTML file so that it is packaged with the rest of my application and how should I included it in the webview component? Is including the HTML file even possible using expo?

1 Like

#2

You should be able to just require the .html file and then put the content into https://facebook.github.io/react-native/docs/webview.html#source.

0 Likes

#3

I’ve tried including a html file inside a WebView using the following syntax:

render() {
    return (
            <WebView
              source={{ html: require("../web/payment.html") }}
              startInLoadingState
              scalesPageToFit
              javaScriptEnabled
              style={{ flex: 1 }}
            />
    );
  }

However, I’m getting the following error
"ReferenceError: React is not defined"

indicating that it is looking for React in the HTML file. At least I do have confirmation that the HTML file is being loaded.

Any idea why I’m getting the above reference error?

0 Likes

#4

for android, how do we target to file:///android_asset??

0 Likes