-1

I dont know what is the problem here, setInterval doesnt wait interval time i set it to wait. First it waits it but after that it keeps doing that x times ms And this code is in react.js render

        setInterval(() => {
            console.log("moi")
        }, 4000)
        return(
            <div>
                <h1>{}</h1>
                <h1></h1>
                <button><h1>Paina</h1></button>
            </div>
        )
    }
Calvin Nunes
  • 6,376
  • 4
  • 20
  • 48

1 Answers1

1

By doing set a setInterval inside of your render, you will creating more instances of this than you bargained for. If you're using classes, place this inside of your constructor().

constructor(props){
  super(props);
  // You may want to assign this to a variable so you can stop it if need be
  setInterval(() => console.log("moi"), 4000);
}

render(){
  return(
    <div>
      <h1></h1>
      <h1></h1>
      <button><h1>Paina</h1></button>
    </div>
  );
}
Miroslav Glamuzina
  • 4,472
  • 2
  • 19
  • 33