As i have heard of, react's require()
only uses static url not variables, that means that you have to do require('/path/file')
, take a look at this issue on github and this one for more alternative solutions, there are a couple of other ways to do it!
for e.g
const images = {
profile: {
profile: require('./profile/profile.png'),
comments: require('./profile/comments.png'),
},
image1: require('./image1.jpg'),
image2: require('./image2.jpg'),
};
export default images;
then
import Images from './img/index';
render() {
<Image source={Images.profile.comments} />
}
from this answer
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…