taro hook 倒计时setTimeout版
const Index = () => {
const [count, setCount] = useState(60)
useEffect(() => {
setTimeout(() => {
if (count > 0) {
console.log(count);
setCount(count - 1); // 在这不依赖于外部的 `count` 变量
}
}, 1000);
}, [count])
return (
<View className='wrapper'>
倒计时{count}
</View>
);
};