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>
);
};
posted @ 2021-11-24 11:12  Edison~~  阅读(378)  评论(0编辑  收藏  举报