我目前正在学习 React 中的钩子概念并试图理解下面的示例。
import { useState } from 'react';function Example() { // Declare a new state variable, which we'll call "count" const [count, setCount] = useState(0); return ( <div> <p>You clicked {count} times</p> <button onClick={() => setCount(count + 1)}> Click me </button> </div> );}
上面的例子增加了处理函数参数本身的计数器。如果我想在事件处理函数中修改计数值怎么办
考虑下面的例子:
setCount = () => { //how can I modify count value here. Not sure if I can use setState to modify its value //also I want to modify other state values as well here. How can I do that}<button onClick={() => setCount()}> Click me</button>
欢迎分享,转载请注明来源:内存溢出