I receive an array of objects as props within the Quote component I can access the props find but when I try to go deeper to the Object it said Cannot read property ‘id’ of undefined I have tried multiple things but can’t find out what’s wrong
const arrOfQuotes = [
{
id: 0,
author: "Paulette Henry",
body: "God is my Faith and Path that lay foundation upon my Life"
},
{
id: 1,
author: "Adrian Anderson",
body: "Today is yours tomorrow is mine"
},
{
id: 2,
author: "Nassim Nicholas Taleb",
body: "The inability to predict outliers implies the inability to predict the course of history, given the share of these events in the dynamics of events."
},
{
id: 3,
author: "Brian Lonsdorf",
body: "A spot of code is referentially transparent when it can be substituted for its evaluated value without changing the behavior of the program."
},
{
id: 4,
author: "George Bernard Shaw",
body: "Custom will reconcile people to any atrocity, and fashion will drive them to acquire any custom."
},
{
id: 5,
author: "Kim Eric Drexler",
body: "TRibosomes are proof that nanomachines built of protein and RNA can be programmed to build complex molecules."
},
{
id: 6,
author: "Doug Stanhope",
body: "Life is like animal porn: it's not for everyone."
},
{
id: 7,
author: "Mark Weiser",
body: "The most profound technologies are those that disappear. They weave themselves into the fabric of everyday life until they are indistinguishable from it."
},
{
id: 8,
author: "Jeff Atwood",
body: "If you know (or even suspect!) your database was exposed, the very first thing you should do is reset everyone's password."
},
{
id: 9,
author: "Brian Tomasik",
body: "We can interpret any piece of matter as being conscious if we want to, but in many cases it doesn't make sense to most of us to speak that way. Panpsychism is analogous to 'pantableism' -- the view that tableness is intrinsic to all matter. There is some sense in which you can interpret any piece of matter as being a table. After all, for any (solid) clump of atoms, you can put stuff on it, and it can support the things that it holds. But this definition is really a stretch for most objects. So it is with saying that everything is conscious."
},
{
id: 10,
author: "Kim Eric Drexler",
body: "Ribosomes are proof that nanomachines built of protein and RNA can be programmed to build complex molecules."
}
];
let Quote = (props) => {
const ranNum = props.value.randomNumber;
console.log("Props ran num",ranNum);
let arr = props.value.quotes.map((data) => data).filter((data) => data.id == ranNum);
console.log("Props Arr",arr);
return <div>
<p id="author"></p>
{console.log("Props Print out", props.value.quotes[props.value.randomNumber].id) }
<p id="text"> </p>
</div>
}
class App extends React.Component {
constructor(props){
super(props);
this.state = {
randomNumber: 0,
quotes: []
}
this.handleClick = this.handleClick.bind(this);
this.randomNumberGenerator = this.randomNumberGenerator.bind(this);
}
componentDidMount(){
this.setState({
quotes: [...arrOfQuotes]
})
}
handleClick(){
this.setState({
randomNumber: this.randomNumberGenerator()
});
}
randomNumberGenerator () {
return Math.floor((Math.random() * 10));
};
render() {
console.log(this.state);
console.log(this.randomNumberGenerator());
return (
<div id="quote-box">
<h1> Random Quote Machine </h1>
<div className="prettier">
<Quote value={this.state} />
</div>
<button id="new-quote" onClick={this.handleClick}>New Quote</button>
</div>
)
}
}
ReactDOM.render(
<App />,
document.getElementById('root')
);