Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useCountDown中的leftTime并没有正确支持动态设置 #2717

Open
baixiaoyu2997 opened this issue Jan 9, 2025 · 0 comments
Open

useCountDown中的leftTime并没有正确支持动态设置 #2717

baixiaoyu2997 opened this issue Jan 9, 2025 · 0 comments

Comments

@baixiaoyu2997
Copy link

baixiaoyu2997 commented Jan 9, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant