function Counter() {
const [count, setCount] = useState(0);
const [calculation, setCalculation] = useState(0);
useEffect(() => {
setCalculation(() => count * 2);
}, [count]); // <- add the count variable here
return (
<>
<p>Count: {count}</p>
<button onClick={() => setCount((c) => c + 1)}>+</button>
<p>Calculation: {calculation}</p>
</>
);
}
我对这一职能的不理解是:
setCalculation(() => count * 2); setCount((c) => c + 1);
They do the similar work, but why does the first line NOT have the parameter? Does this make any difference between two lines?
为什么使用“c”而不是“count”? (While `count'在前线使用)。
谢谢。
我认为他们也做了同样的工作,但我现在并不肯定。