I try to load the local .html
file into WebView
in React Native:
// load local .html file
const PolicyHTML = require('./Policy.html');
// PolicyHTML is just a number of `1`
console.log('PolicyHTML:', PolicyHTML);
// will cause an error: JSON value '1' of type NSNumber cannot be converted to NSString
<WebView html={PolicyHTML} />
The .html
file should be read as a string, not as a resource representative.
How can I load the .html
file into WebView
in React Native?
By the way, what is the type of those resource representatives from require()
? Is it number
?
try it:
const PolicyHTML = require('./Policy.html');
<WebView
source={PolicyHTML}
style={{flex: 1}}
/>