-1
I’d like to get the names of the Pokemons and the images.
I use the following code:
import React, { Component } from 'react';
import api from "../../services/api";
import './styles.css';
export default class Main extends Component {
state = {
pokemons: [],
}
componentDidMount(){
this.loadpokemon();
}
loadpokemon = async () => {
const response = await api.get('/type/electric');
this.setState({ pokemons: response.data.pokemon})
console.log(this.state);
}
render(){
return //<h1>total: {this.state.pokemons.length}</h1> Esse codigo funciona
(
<div className='pokemon-list'>
{this.state.pokemons.map( pokemon => (
<h2>{pokemon.name}</h2>
))}
</div>
);
}
}
For which I receive the error:
Failed to compile
./src/pages/main/index.js
Line 24: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.
This error occurred during the build time and cannot be dismissed.
At the beginning I don’t see the error. This question code is
main/index.js
? You can give an example of this JSON?– Sergio
Yes is main/ index.js and posted the print, using the code "Return <H1>total: {this.state.Pokemons.length}</H1>"
– Cristian Camargo