Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript ReactJS – Trying to set state using time delay

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #240423
    matthisco
    Participant

    Hello,

    By clicking ‘show jackpot’, I want the value to be shown in place of the button for five seconds, then revert back to the original state.

    I cannot get the button to revert back to its original state, can anyone help?

    Using I’m trying to use setTimout to reset my state, here is my fiddle:

    https://jsfiddle.net/mharrisweb/pss04s5L/68/

    #240474
    tomek
    Participant

    Hi,

    try this:

        delayState: function() {
            setTimeout(() => {
                this.setState({
                clicked: false
              })
            }, 2000);
        },
    

    I am using an arrow function here, so setTimeout won’t carry its this inside the body.

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.