【发布时间】:2020-09-29 17:17:00
【问题描述】:
const Counter = () => {
const [count, setCount] = useState(0);
// return <button onClick={setCount(count + 1)}>{count}</button>;
return <button onClick={() => setCount(count + 1)}>{count}</button>;
};
我知道注释掉的行会导致无限循环,但我想知道为什么会这样。 setCountdispatch 函数不是只在点击时调用吗?
【问题讨论】:
标签: javascript reactjs react-hooks use-state