Why is clearTimeout not clearing the timeout in this react component?
问题 I am attempting to clear a former timeout before initiating a new timeout, because I want messages to display for 4 seconds and disappear UNLESS a new message pops up before the 4 seconds is up. The Problem: Old timeouts are clearing the current message, so clearTimeout() is not working in this component, in this scenario: let t; // "t" for "timer" const [message, updateMessage] = useState('This message is to appear for 4 seconds. Unless a new message replaces it.'); function clearLogger() {