Answer the question
In order to leave comments, you need to log in
How to correctly receive data from the api and go through the map?
Good afternoon. I am learning, sending a request to get data [] api and trying to draw them using the map method in React, but it says that Cannot read property 'map' of undefined. Checked the data come to the console. What is the problem ?
import React from 'react'
class Grivna extends React.Component{
constructor(props){
super(props);
this.state ={
items: []
}
}
componentDidMount(){
fetch(`https://bank.gov.ua/NBUStatService/v1/statdirectory/exchange?json`)
.then(res => res.json())
.then(
(result) => {
this.setState({
items: result.items
})
}
)
}
render(){
debugger
const {items} = this.state;
return(
<ul>
{items.map(item => (
<li key={item.id}>{item.txt} {item.cc} {item.exchangedate}</li>
))}
</ul>
)
}
}
export default Grivna
Answer the question
In order to leave comments, you need to log in
componentDidMount(){
fetch(`https://bank.gov.ua/NBUStatService/v1/statdirectory/exchange?json`)
.then(res => res.json())
.then(
(result) => {
this.setState({
items: result
})
}
)
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question