You need to get HTML string. In WEB React you can render JSX by ReactDom but in ReactNative you can't do it. The easiest way is generating html string according to your jsx and data. You can put everthing there. I show you several examples.
class MyInlineWeb extends Component {
componentDidMount(){ // Do something}
renderHtmlAndroid = (data) => {
return `<div>
<style>
.block {}
</style>
<div class="block">${data}<div>
<div>`
}
renderHtmliOs = (data) => {
return `<!DOCTYPE html>
<html>
<head>
<title>Title</title>
<meta charset="UTF-8" />
</head>
<body>
<div id="app">${data}</div>
</body>
</html>`
}
render() {
return (
<WebView
originWhitelist={['*']}
source={{html: isAndroid ? this.renderHtmlAndroid([]) : this.renderHtmliOs([])}}
/>
);
}
}
Answer from Jiml on Stack Overflow
» npm install react-native-webview
Videos
» npm install react-electron-web-view
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!