1

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)
}
jdip88
  • 427
  • 2
  • 9
  • 23

1 Answers1

0

Not sure, but maybe there is a problem with setTimeout which purpose is to trigger event once, so you can try with setInterval which purpose is execute function unlimited number of times.

Maybe you can check more here.

smgeog
  • 15
  • 1
  • 7