I have this API call that returns types of Pokemon as in:
["Grass", "Poison", "Fire", "Flying", "Water", "Bug", "Normal", "Electric", "Ground", "Fighting", "Psychic", "Rock", "Ice", "Ghost", "Dragon"]
This is a result of a function that takes all Pokemon values and filters out duplicates and such. The same function is used to take these values and populate the select options:
let pokemonSingleType = (() => {
let types = pokemonData.reduce((acc, { type }) => (acc.push(...type), acc), [])
types = new Set(types);
types = [...types];
console.log(types);
return <option>
{types}
</option>
})();
That gets rendered below:
<select value={searchType} onChange={updateSearchByType.bind(this)}
className="formcontrol" id="typeSelect">
{pokemonSingleType}
</select>
The issue is that I get the whole array as one Select option value. Please see image below:
The output is as below:
Also, when I do a for loop before, it stops at the first iteration:
let pokemonSingleType = (() => {
let types = pokemonData.reduce((acc, { type }) => (acc.push(...type), acc), [])
types = new Set(types);
types = [...types];
for(let i =0; i< types.length; i++){
return <option>
{types[i]}
</option>
}
})();
