setstate to false after 10 sec react native 1

setstate to false after 10 sec react native

saveAndContinue: function(e) {
    e.preventDefault()

    if(this.state.submitted==false) {
        email = this.refs.email.getDOMNode().value
        this.setState({email: email})
        this.setState({submitted: !this.state.submitted});
        setTimeout(function(){
             this.setState({submitted:false});
        }.bind(this),10000);  // wait 5 seconds, then reset to false
   }
}

Here is what the above code is Doing:
1. When the user clicks the button, the saveAndContinue function is called.
2. The function checks to see if the state variable submitted is false.
3. If it is false, it sets the state variable email to the value of the email input field.
4. It then sets the state variable submitted to true.
5. It then sets a timeout function to reset the state variable submitted to false after 5 seconds.
6. If the state variable submitted is true, the function does nothing.

Similar Posts