javascript - react component re rendered multiple times when trying to invoke itself? -
code:
mymethod = () => { settimeout(()=> { if(!this.state.otherfunchasbeencalled) { this.mymethod() } },5000) }
so otherfunchasbeencalled
state set true if other function called. wanted here when mymethod
invoked, after 5 seconds, if other function not called sets otherfunchasbeencalled
state true, invoke mymethod
again. re renders component multiple times. help?
how this?
mymethod = () => { settimeout(()=> { if(!this.state.otherfunchasbeencalled) { // wait 5 sec check this.setstate( {otherfunchasbeencalled: true}, // update state this.mymethod // run again after state has been set } },5000) }
Comments
Post a Comment