Hi just wondering if anyone could explain this syntax error to me. Im mapping over and object and trying to access the values through object.keys
const getPokemonCard = (pokemonId) => {
const { id, name } = pokemonData[`${pokemonId}`]
const sprite = `https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/${pokemonId}.png`
return (
<Grid item xs={4} key={pokemonId}>
<Card>
<CardMedia
className={classes.cardMedia}
image={sprite}
style={{
width: '130px',
height: '130px'
}}
/>
<CardContent>
<Typography>
{`#${id}. ${firstLetterUpperCase(name)}`}
</Typography>
</CardContent>
</Card>
</Grid>
)
}
I have figured out a solution but dont quite understand it.
const firstLetterUpperCase = (name) => {
name.charAt(0).toUpperCase() + name.slice(1);
}
gives me an error
Line 19:5: Expected an assignment or function call and instead saw an expression no-unused-expressions
Search for the keywords to learn more about each error.
but when i remove the brackets it works
const firstLetterUpperCase = (name) =>
name.charAt(0).toUpperCase() + name.slice(1);
firstLetterUpperCasedoesn't return anything. The second uses an implicit return. developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… - evolutionxboxreturnthe result from the function. In the second, because of how an implied return with an arrow function works, you don't. - Andy