hooks
hooks copied to clipboard
useCountDown中的leftTime并没有正确支持动态设置
const [targetDate, setTargetDate] = useState<number>();
const [countDown] = useCountDown({
targetDate,
});
const rotatingTime = 1;
const onResend = () => {
if (countDown !== 0) return;
setTargetDate(Date.now() + 10 * 1000);
setIsRotating(true);
setTimeout(() => {
setIsRotating(false);
}, rotatingTime * 1000);
props.onResend?.();
};
这样是可以的,但是改为leftTime就不生效了:
const [leftTime, setLeftTime] = useState();
const [countDown] = useCountDown({ leftTime });
const rotatingTime = 1;
const onResend = () => {
if (countDown !== 0) return;
setLeftTime(10 * 1000);
setIsRotating(true);
setTimeout(() => {
setIsRotating(false);
}, rotatingTime * 1000);
props.onResend?.();
};
version: 3.8.4
@crazylxr 看了下useEffect里面拿target做依赖,leftTime没变化的时候不会重启计时,后续感觉是不是可以像vueuse那样多返回一些操作函数,比如reset重置计时
@crazylxr 看了下useEffect里面拿target做依赖,leftTime没变化的时候不会重启计时,后续感觉是不是可以像vueuse那样多返回一些操作函数,比如reset重置计时
![]()
来个 pr ?