This is currently how my code looks
import React from 'react';
import './App.css';
class App extends React.Component {
state = {
apiData: []
}
render() {
console.log('api data is')
return (
<div>
<center>
<h1 id="title">hello something</h1></center>
<h1 id="date">{this.state.apiData.title}</h1>
</div>
)
}
componentDidMount() {
fetch('http://www.mocky.io/v2/5dece3d333000052002b9037')
.then(response => response.json())
.then(data => {
this.setState({
apiData: data
})
})
console.log("component fetched data")
}
}
export default App
I get this error when I try access something that has a value but when I do this
<h1 id="date">{this.state.apiData.date}</h1>
It works
not too sure how to fix as everything I have seen thus far is for data they have created through a const or let as opposed to fetching data from an API