双击事件怎么解决防止触发单击事件
ref + settimeout
为啥不能使用 state / 静态变量
state 就存在闭包
静态变量无效

handleSingleClick = () => { const timer = setTimeout(() => { if (!this.isDoubleClick) { console.log("Single click"); } this.isDoubleClick = false; clearTimeout(timer); this.timerRef.current = null; }, 200); this.timerRef.current = timer; } handleDoubleClick = () => { this.isDoubleClick = true; const timer = this.timerRef.current; if (timer) { clearTimeout(timer); this.timerRef.current = null; } console.log("Double click"); }