useCountDown中的leftTime并没有正确支持动态设置
- Dominant language
- TypeScript
- Stars
- 15k
- Forks
- 2.8k
- Avg merge
- 15h 7m
- Merged PRs (30d)
- 2
Description
```ts
const [targetDate, setTargetDate] = useState();
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就不生效了:
```ts
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
Contributor guide
Research direction
Start at the useCountDown hook and reproduce the two examples from the issue, comparing dynamic updates through targetDate and leftTime. The work is done when updating leftTime after the countdown reaches zero behaves like updating targetDate, with the relevant behavior covered by the hook's tests if available.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100