1
You guys talking? All right?
I have a problem in my React application with an api, you could help me?
I want to show the names of the Pokemons of an api, but the array that gets the names of the Pokemons is inside "Results" in the "date" of the api, so whenever I try to run the code of "Undefined" as if there was an array for it to read.
I have not yet put the surrender, but how do I warn the this.setState({pokemon: response.data})
that the array is within Results?
example: this.setState({pokemon: response.data"results"})
import api from './api';
class App extends Component{
state={
pokemon: [],
}
async componentDidMount(){
const response = await api.get('');
console.log(response.data);
this.setState({pokemon: response.data})
}
render(){};
}
export default App;
import axios from 'axios';
const api = axios.create({
baseURL: 'https://pokeapi.co/api/v2/pokemon'
})
export default api;
Try to catch it like this:
response.data.results
– adventistaam