Search code examples
javascriptreactjsreact-nativerequire

Why require not accepting variable as path?


I assigned file path to a variable and tried to pass it to require function but it's not accepting it!

If require not accepting variable as parameter then how I'll give it?

Click to see code


Solution

  • you should try importing the image like so:

    import iconPath from './united-kingdom.png';
    

    and then you can use it like this:

     source={iconPath}