For example I have this <i>
for Icon element
<i style={{ backgroundImage: `url(${'./images/names/Mike.svg'}` }}/>
I know I can import an image by importing them individually according to this post
but it's not feasible in my case since I need to import a lot of them.
Is there a workaround to make this possible in Create React App
?
Edit: I'm currently doing this
backgroundImage: `url(${require(`./images/names/${name}.svg`)})`
but still not working, unless I hard code the name
backgroundImage: `url(${require(`assets/images/names/Mike.svg`)})`
which is not viable in my case.
Here are three ways to import an image (SVG and PNG) into a React project. You can use either file type with all three options.
See examples below: