31
loading...
This website collects cookies to deliver better user experience
const htmlContent = `
<h1>This HTML snippet is now rendered with native components !</h1>
<img source="./src/assets/michael.jpg"/>
<h2>Enjoy a webview-free and blazing fast application</h2>
<em>Some random sentence!</em>
`;
<HTML
renderers={{
img: (attribs) => {
const imagePath = attribs.source;
console.log(imagePath);
return (
<Image
key={attribs.source}
style={styles.imageContainer}
source={require('./src/assets/michael.jpg')}
/>
);
},
}}
source={{html: htmlContent}}
contentWidth={contentWidth}
/>
<img/>
tag and voila, you’re done!”<img>
tag.<img source="./src/assets/michael.jpg"/>
const htmlContent = `
<h1>This HTML snippet is now rendered with native components !</h1>
<img source="./src/assets/michael.jpg"/>
<h2>Enjoy a webview-free and blazing fast application</h2>
<em>Some random sentence!</em>
`;
<HTML
renderers={{
img: (attribs) => {
const imagePath = attribs.source;
console.log(imagePath);
return (
<Image
key={attribs.source}
style={styles.imageContainer}
source={require('./src/assets/michael.jpg')}
/>
);
},
}}
source={{html: htmlContent}}
contentWidth={contentWidth}
/>
"./src/assets/michael.jpg"
require('./src/assets/michael.jpg);
to
require(imagePath);
[Error: TransformError App.js: App.js:Invalid call at line 31: require(imagePath)]
const imagesList = {
dwight: require('./src/assets/dwight.jpg'),
michael: require('./src/assets/michael.jpg)
}
const htmlContent = `
<h1>This HTML snippet is now rendered with native components !</h1>
<img source="./src/assets/michael.jpg"/>
<h2>Enjoy a webview-free and blazing fast application</h2>
<em>Some random sentence!</em>
`;
<HTML
renderers={{
img: (attribs) => {
const imagePath = attribs.source;
return (
<Image
key={attribs.source}
style={styles.imageContainer}
source={imagesList[imagePath]}
/>
);
},
}}
source={{html: htmlContent}}
contentWidth={contentWidth}
/>
const imagesList = {
dwight: require('./src/assets/dwight.jpg'),
michael: require('./src/assets/michael.jpg)
}
<img source="michael"/>
<Image
key={attribs.source}
style={styles.imageContainer}
source={imagesList[imagePath]}
/>
<img source="michael"/>
to
<img source ="dwight"/>