Currently, I have some code that is able to set a variable to be the same name as one of the import statements that call the images. I was trying to find a way to then use this to display the image. My code looks at some data and comes out with a name, say 'Bill', and assigns it to name. It would then try to show the image with the following code:
<img src={name} alt ='' />
instead of using
<img src={Bill} alt ='' />
I have an import statement at the top that is 'import Bill from path' and this is able to produce the bottom statement, but I would like for it to display with the variable. Let me know if this is too confusing so I can explain it better or you need more code and I could provide.
Added some better code:
import React from 'react'
import Bill from '../../img/players/Bill.jpg'
import Grant from '../../img/players/Grant.jpg'
const CharacterItem = ({ info, index }) => {
var name = info[index][0].last_name
console.log(name) //outputs Bill
console.log(name === Bill) //outputs false
return (
<img src={'../../img/players/' + name} alt ='' />