我是 React 新手,我正在尝试学习 React 函数组件状态。我想知道为什么我们需要做onClick={() => setCount(count + 1)}
而不是onClick={setCount(count + 1)}
import React, {useState} from 'react';
function Counter() {
const [count , setCount] = useState(0);
return (
<div>
<button onClick={setCount(count+1)}> + </button>
{count}
</div>
);
}
export default Counter;