I have this class component
import React, {Component} from 'react';
import Author from './author';
import NewQuote from './new-quote';
import TweetQuote from './tweet-quote';
import Text from './text';
import quotes from './quotes';
class App extends Component{
constructor(){
super()
this.state = {quotes, n: this.onLoadHandle() }
this.onLoadHandle = this.onLoadHandle.bind(this)
}
onLoadHandle(){
this.max = this.state.quotes.length;
this.randInt = Math.round(Math.random() * 10);
while(this.randInt < 0 || this.randInt >= this.max){
this.randInt = Math.round(Math.random() * 10);
}
return this.state.quotes[this.randInt]
}
render(){
return(
<div id = 'quote-box'>
<Text quote = {this.onLoadHandle().quote}/>
<Author author = {this.onLoadHandle().author} />
<TweetQuote />
</div>
)
}
}
export default App;
However i keep getting this particular error
TypeError: Cannot read property 'quotes' of undefined
in the ./quotes
file i have this array
const quotes = [
{
id: '1',
quote: 'The Way To Get Started Is To Quit Talking And Begin Doing.',
author: 'Walt Disney'
},
{
id: '2',
quote: "Don’t Let Yesterday Take Up Too Much Of Today.",
author: 'Will Rogers'
},
{
id: '3',
quote: "It’s Not Whether You Get Knocked Down, It’s Whether You Get Up.",
author: "Vince Lombardi"
},
{
id: '4',
quote:"If You Are Working On Something That You Really Care About, You Don’t Have To Be Pushed. The Vision Pulls You.",
author: "Steve Jobs"
},
{
id: '5',
quote: " Failure Will Never Overtake Me If My Determination To Succeed Is Strong Enough.",
author: "Og Mandino"
}
]
export default quotes;
Can someone explain to me what is happening here?