Since it's this.randInt and not this.props.randInt, it should be this.randInt everywhere.
question is a class field, which is syntactic sugar for constructor code:
class Question extends React.Component{
constructor(props){
super(props);
this.question = {
quest : questions[this.props.randInt].quest,
answers : questions[this.props.randInt].answers,
correct : questions[this.props.randInt].correct
}
this.randInt = Math.floor(Math.random() * 1);
}
}
Class field declarations go first in the constructor body. Since an explicit constructor is not needed here, it should be:
class Question extends React.Component{
randInt = Math.floor(Math.random() * 1);
question = {
quest : questions[this.randInt].quest,
answers : questions[this.randInt].answers,
correct : questions[this.randInt].correct
}
}
With class fields, explicit constructor is needed only for synchronous side effects that previously occurred in deprecated componenentWillMount lifecycle method.
questions? Also, what are you trying to use thequestionObject for? When do you want to initialize it?this.props.randIntdothis.randIntMath.floor(Math.random() * 1)returns always0.