How can I add variable bgImg to background-image URL?
let bgImg = props=>props.bgImg;
//this will show error
export const Users = styled.div`
background-image: url(${require('../../assets/images/' + {bgImg} + '.svg')});
background-image: url(${require('../../assets/images/' + ${bgImg} + '.svg')});
`;
I have tried this and it didn't work
let x = '../../assets/images/';
let bgImg = props=>props.bgImg;
let result = x + bgImg + ".svg";
Result with error
../../assets/images/function bgImg(props) {
return props.bgImg;
}.svg
How can I get that return property?
bgImgas a function. What is it you expect to pass into that function? Nothing in what you've shown actually calls it.propsis already in scope, why not just dolet bgImg = props.bgImg?require, it should be easier one.