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

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -