I am importing images and naming them img1, img2, img3 etc. I want to be able to increase the number on the name when I click a button, but when I concatenate or use template literals it returns a string.
Here for clarity:
import img1 from 'img1.jpg'
import img2 from 'img2.jpg'
import img3 from 'img3.jpg'
const [ num, setNum ] = useState(1)
function handleNextClick() {
setNum(num + 1)
}
This is where my problem is:
<img src={ 'img' + num} alt="" />
It returns as:
<img src='img1' alt="" />
I want:
<img src={img1} alt="" />