Reasons to use React Native instead of React + WebView?
React Native Webview not loading any url (React native web view not working) - Stack Overflow
What is the right way to use WebView in React Native - Stack Overflow
Debugging WebView in React Native apps
Videos
This will probably sound silly coming from an experienced dev, but what are the reasons for using React Native instead of building a responsive version of an existing React web app and rendering it inside something like a WebView?
I've just started to dabble into mobile development, but from a quick glance WebView seems to have feature parity with native APIs if we include native plugins for various packagers (PhoneGap/Cordova, Capacitor) in the picture. For example, it's possible to send push notifications or use geolocation APIs from such an app.
Assuming I can optimize a web app really well, what would be the reasons to use React Native instead?
Any thoughts are appreciated!
I had this issue. WebView would render when it was the only component returned, but not when nested in another View component.
For reasons I'm not entirely sure of the issue was resolved by setting a width property on the WebView component.
class App extends React.Component {
render() {
return (
<View style={styles.container}>
<WebView
source={{uri: 'https://www.youtube.com/embed/MhkGQAoc7bc'}}
style={styles.video}
/>
<WebView
source={{uri: 'https://www.youtube.com/embed/PGUMRVowdv8'}}
style={styles.video}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'space-between',
},
video: {
marginTop: 20,
maxHeight: 200,
width: 320,
flex: 1
}
});
I'm facing same issue. What I observed is that WebView doesn't work if it's nested. If component returns just WebView, then everything is fine.
» npm install @dr.pogodin/react-native-webview
The easiest way to inspect your WebView in React Native is to just use the Remote JS Debugger. This has the added benefit for working in either iOS or Android, since you're simply debugging the JavaScript that is running on your application.
In order to see the WebViews, you'll want to go a step further and use Chrome's Remote Devices.

If you click on Inspect next to your Document matching the index.html you're wanting to debug, you can then see all of the logs in the console for that WebView.

I added a <script> inside of index.html in the <header> that just does the following:
console.log('This is showing in the console!')
You can see in the image above, its logging out in the DevTools that is inspecting that WebView.
For more on react-native-webview debugging guide head on to Debugging Guide Docs
Not sure if it's relevant for your case, but if you're also developing for iOS there's a pretty easy way to do it on a Mac + iOS simulator (or a real device). At the end, a React Native WebView creates a native web-view (UIWebView on iOS, and a WebView on Android), so any debugging method which works for web apps applies here as well.
- On your iOS simulator (or device): Open the settings app -> Safari -> Advanced -> Turn Web inspector ON.
- Open Safari on your Mac and enable developer mode in: Preferences -> Advanced -> Show developer menu in menu bar (checkbox at the bottom).
- In Safari on your mac you will now have the "Develop" menu. Open it and find the Simulator or your connected device. When you hover this menu item you will see the currently loaded page. This works for any page loaded on the device, whether it's shown in a
WebViewinside your app or on the system browser. - Once you select the page, you can use the Safari Web Inspector to pretty much do anything: view all loaded resources, network requests, highlight elements, console logs, debug the JS code and more.
» npm install react-native-webview