import React from 'react';
import { View, Image } from 'react-native';
const MyComponent = ({ item }) => {
const imageSource = require(`./assets/${item}.png`);
return (
<View>
<Image source={imageSource} />
</View>
);
};
export default MyComponent;
result:
error:
componentsmultipleProductsImageReader.tsx:
componentsmultipleProductsImageReader.tsx:Invalid call at line 4:
require("../assets/" + item + ".png")
How to render the image in react-native dynamically? like my sample above.
2
Answers
Try rendering your Image as shown below:
This will render your image dynamically.
First of all print item result on console log if image have a already file extension then remove .png from require(
./assets/${item}.png
);Note :- Must check dynamic item image path exist in local assets folder.