I have this Error, but i don’t get why this is happening. Because i get list of object and now with this.state.quoteList.quotes[0] i want to select one element of that object array. This is the entire Component.
How do I solve this ?
Why this is happening ?
I already search for it and couldn’t find answer.
import React, {Component} from 'react';
import Footer from './Footer';
let listOfColors = ["#1abc9c", "#2ecc71", "#3498db", "#9b59b6",
"#34495e", "#16a085", "#27ae60", "#2980b9", "#8e44ad", "#2c3e50",
"#f1c40f", "#e67e22", "#e74c3c", "#f39c12", "#d35400", "#c0392b"];
class RandomQuote extends Component{
constructor(){
super();
this.state = {
quoteList: []
};
this.changeColor = this.changeColor.bind(this);
this.tweet = this.tweet.bind(this);
}
componentDidMount() {
fetch("https://gist.githubusercontent.com/camperbot/5a022b72e96c4c9585c32bf6a75f62d9/raw/e3c6895ce42069f0ee7e991229064f167fe8ccdc/quotes.json")
.then(response => response.json())
.then(data => {
this.setState({
quoteList: data
})
})
}
changeColor(){
console.log("Working!");
}
tweet(){
console.log("Working!");
}
render(){
console.log(this.state.quoteList.quotes[0]);
return(
<div className="Random-Quote">
<blockquote className="blockquote">
<p id="text">Quote Placeholder</p>
<footer className="blockquote-footer" id="author">Author Placeholder</footer>
</blockquote>
<div className="Buttons-stage">
<button id="shareMessage" className="btn" onClick={this.tweet()}></button>
<button id="getMessage" className="btn" onClick={this.changeColor()}>New Quote</button>
</div>
<Footer />
</div>
);
}
}
export default RandomQuote;