I'm using react-google-maps but I think my question applies a general user case. I want to dynamically load an icon, using a url passed in as a prop. But I find if I use a variable I get an error. Please see below:
When I require and icon using a string it works fine e.g.
icon={require('../assets/myPng.png')}
But if my png path is a variable for example
let url = '../assets/myPng.png'
icon={require(`${url)`}
I get error:
cannot find module '../assets/myPng.png'
Can anyone tell me what is going on ?
if I use icon={require(url}
, that fails also.