表单新增蜜罐反垃圾字段;修复 CookieConsent 的 react-hooks/set-state-in-effect lint 报错

This commit is contained in:
2026-08-07 14:49:29 +08:00
parent 3f05bd16e1
commit 1abadd04b8
2 changed files with 15 additions and 0 deletions
+2
View File
@@ -10,8 +10,10 @@ export default function CookieConsent() {
useEffect(() => {
// 仅在浏览器已明确同意/拒绝前展示,避免每次访问重复弹出。
// localStorage 只能在客户端读取,此处属于“挂载后同步一次性客户端状态”的合理用法。
const consent = window.localStorage.getItem(CONSENT_STORAGE_KEY);
if (!consent) {
// eslint-disable-next-line react-hooks/set-state-in-effect -- 首次挂载后读取 localStorage 决定是否展示横幅,属预期用法
setVisible(true);
}
}, []);