I have a quiz application that I am creating and I have a Question component. Each time the question component renders, I want to start a 60 second timer. If the user does not answer or leaves the application, after 60 seconds I want to redirect them to the home page where the next user would be able to start the quiz from the beginning.
I also had another question about the componentWillMount()
function. I have that same question componenent that has 6 different instances or ('questions') as you would say. When i go from question 1 to question 2, the componentWillMount()
function does not refire. It only fires on the first render of that component, even though they are different instances. I need to make sure that timer restarts on each components rendering.
What would be the best way of doing this? Is it best to use the props.history.push('/')
.
componentWillMount(){
setTimeout(() => {
console.log('this ran')
this.props.history.push('/');
}, 60000)
}