I am trying to pull data => Crypto Exchange rates. See API spec here: https://rapidapi.com/coingecko/api/coingecko?endpoint=apiendpoint_a6893c7b-2094-4a19-9761-0c0306fe741a but getting TypeError: Cannot read property 'map' of undefined
Error:
32 |
33 | return (
> 34 | <ul>
| ^ 35 | { this.state.rates.map(i => <li>{i.data.rates}</li>)}
36 | </ul>
37 | )
Code:
import React from 'react';
import './App.css';
import prettyFormat from 'pretty-format';
import axios from 'axios';
class App extends React.Component {
state = {
rates: []
}
componentDidMount() {
axios({
"method":"GET",
"url":"https://coingecko.p.rapidapi.com/exchange_rates",
"headers":{
"content-type":"application/octet-stream",
"x-rapidapi-host":"coingecko.p.rapidapi.com",
"x-rapidapi-key":"f4756b8409msh762478a357cd070p10685fjsnce9080fa5478"
}
})
.then((response)=>{
console.log(response)
})
.then(rates => this.setState({ rates}))
}
render() {
console.log(prettyFormat(this.state.data))
return (
<ul>
{ this.state.rates.map(i => <li>{i.data.rates}</li>)}
</ul>
)
}
}
export default App;```