From 388429a79c1f710b83de047d9018a90411bdcc3e Mon Sep 17 00:00:00 2001 From: Li1304553726 <1304553726@qq.com> Date: Tue, 18 Nov 2025 15:52:22 +0800 Subject: [PATCH] 1 --- app/components/header/Header.tsx | 13 +++++++------ app/routes/news.tsx | 10 +++++++++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/app/components/header/Header.tsx b/app/components/header/Header.tsx index a707a6e..1714f94 100644 --- a/app/components/header/Header.tsx +++ b/app/components/header/Header.tsx @@ -4,27 +4,28 @@ export function Header(){ const [currentTime, setCurrentTime] = useState(new Date()); useEffect(() => { + // setInterval是 JavaScript 中的一个全局函数,用于重复执行代码 const timer = setInterval(() => { setCurrentTime(new Date()); }, 1000); // 每秒更新一次 // 清理定时器 - return () => clearInterval(timer); - }, []); + return () => clearInterval(timer);// 只在组件卸载时清理定时器 + }, []); // 只在组件首次挂载时设置定时器 return (