How To Solve The React Hook Closure Issue?
问题 import React, { useState} from "react"; import ReactDOM from "react-dom"; function App() { const [count, setCount] = useState(0); function handleAlertClick(){ return (setTimeout(() => { alert("You clicked on: " + count); }, 3000)) } return ( <div> <p>You clicked {count} times</p> <button onClick={() => setCount(count + 1)}>Click me</button> <button onClick={handleAlertClick}>Show alert</button> </div> ); } I just want to know if this works the way that I think it does, or if there is a better