I am creating a bulbapedia clone as a side project.
I am trying to have the results page display buttons for the pokemon's typing. As such, I have each button type saved as a little png in an assets/typeBadges folder.
I have all of them bundled in one folder, with an index file exporting them all. I imported the index file into the TypeBadges file.
I am pulling data from pokeapi v2, and then it maps over the results so that I have an array with the one or two types that the pokemon is. (bulbasaur, for example is grass and poison, so I have typesArray with ['grass', 'poison']
How can I make my IMG src correlate to the string(s) in the array? (each button is named for its type exactly, down to casing)
Here is what I have:
import React, {useEffect} from "react";
import '../assets/TypeBadges/index.js';
const TypeBadges = (props) => {
const {result} = props;
const typeArray = [];
useEffect(() => {
result.types.map((type, idx) => (
typeArray.push(type.type.name) ))
console.log(typeArray)}, [])
return (
<div className="type-badges">
<img src ={buttonforTypeArray[0]} />
{typesArray[1] ? <img src={buttonforTypeArray[1]} /> : null }
</div>
)
}
export default TypeBadges;
obviously I dont expect "buttonfortypearray[0]" to work, it's just filler for the sake of the question.
I was thinking of interpolating something like
But the problem I run into is that the typesArray[0] and typesArray[1] end up being strings, which messes up any kind of interpolation or pathing I can think of.
Any help would be greatly appreciated.
Edit: also adding the index file that i'm importing, if that helps/matters.
export {default as dark} from './Dark.png'
export {default as dragon} from './Dragon.png'
export {default as electric} from './Electric.png'
export {default as fairy} from './Fairy.png'
export {default as fighting} from './Fighting.png'
export {default as fire} from './Fire.png'
export {default as flying} from './Flying.png'
export {default as ghost} from './Ghost.png'
export {default as grass} from './Grass.png'
export {default as ground} from './Ground.png'
export {default as ice} from './Ice.png'
export {default as normal} from './Normal.png'
export {default as poison} from './Poison.png'
export {default as psychic} from './Psychic.png'
export {default as rock} from './Rock.png'
export {default as steel} from './Steel.png'
export {default as water} from './Water.png'