我不知道这里是什么问题,setInterval不等待间隔时间,我将其设置为等待。首先,它等待它,但是之后,它继续执行x毫秒 这段代码在react.js渲染中
setInterval(() => {
console.log("moi")
}, 4000)
return(
<div>
<h1>{}</h1>
<h1></h1>
<button><h1>Paina</h1></button>
</div>
)
}
答案 0 :(得分:1)
通过在渲染器中设置setInterval
,您将创建比此议价更多的实例。如果您使用的是类,请将其放在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>
);
}