如何让操作首先运行,以便在页面加载时加载,然后每 4 秒间隔一次?目前,当页面加载时dencrypt等待 4 秒,然后在重复时工作正常 const Home = () => { const { result, dencrypt } = useDencrypt(); React.useEffect(() => { let i = 0; const action = setInterval(() => { dencrypt(values[i]); i = i === values.length - 1 ? 0 : i + 1; }, 4000); return () => clearInterval(action); }, []);
1 回答
守候你守候我
TA贡献1802条经验 获得超10个赞
React.useEffect(() => {
const functionToSet = () => {
console.log("Run");
};
functionToSet();
const timerID = setInterval(functionToSet, 4000);
return () => clearInterval(timerID);
}, []);
添加回答
举报
0/150
提交
取消