Assuming this happens inside the component, save the timeout identifier so that it can be undone later. Otherwise, you will need to save the identifier in another place, which it can access later, for example, an external storage object.
this.timeout = setTimeout(function(), { // Do something this.timeout = null }.bind(this), 3000) // ...elsewhere... if (this.timeout) { clearTimeout(this.timeout) this.timeout = null }
You probably also want any pending timeout also to be canceled in componentWillUnmount() :
componentWillUnmount: function() { if (this.timeout) { clearTimeout(this.timeout) } }
If you have some user interface, which depends on whether the delayed timeout expects, you will want to save the identifier in the corresponding state of the component.
Jonny buchanan
source share