Why is it that the correct count value can be obtained in setinterval after the first click, and then the transformation does not occur again?
import React, { useEffect, useState } from 'react'; const Demo1 = () => { let [count, setCount] = useState(1); const onCountClick = () => { count += 1; setCount(count); }; useEffect(() => { setInterval(() => { console.log(count); }, 1000); }, []); console.log(count); return <button onClick={() => onCountClick()}>test</button>; };
https://stackoverflow.com/questions/67444566/react-hooks-setinterval-why-can-it-be-modified-for-the-first-time May 08, 2021 at 02:04PM
没有评论:
发表评论