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 在压后台时,不执行 onEnd #2374

Closed
JackGuiYang12 opened this issue Nov 20, 2023 · 2 comments
Closed

useCountDown 在压后台时,不执行 onEnd #2374

JackGuiYang12 opened this issue Nov 20, 2023 · 2 comments
Labels
🤔 Need Reproduce We cannot reproduce your problem

Comments

@JackGuiYang12
Copy link

想了解一下 useCountDown 内部使用 setInterval 的原因是什么?因为在大部分时候,setInterval 的问题会比 setTimeout 多

@liuyib
Copy link
Collaborator

liuyib commented Nov 21, 2023

应该不是 setInterval 的问题,看了下内部剩余时间的计算函数,

const calcLeft = (target?: TDate) => {
if (!target) {
return 0;
}
// https://stackoverflow.com/questions/4310953/invalid-date-in-safari
const left = dayjs(target).valueOf() - Date.now();
return left < 0 ? 0 : left;
};

参数 TDate 的类型如下,

image

当输入无法转数字的字符串、null 时,dayjs(target).valueOf() 会得到结果 NaN,而结果等于 0 才会调用 onEnd:

if (targetLeft === 0) {
clearInterval(timer);
onEndRef.current?.();

应该是 calcLeft 函数的计算结果出现 NaN 导致的。不过上述都是猜测,还是得复现才能准确定位问题。

你的问题能否复现呢?不复现的话,也没法做测试 @JackGuiYang12

@crazylxr crazylxr added the 🤔 Need Reproduce We cannot reproduce your problem label Dec 17, 2023
Copy link

Hello @JackGuiYang12. Please provide a online reproduction by forking this link https://codesandbox.io/s/ok2fe or a minimal GitHub repository. Issues labeled by Need Reproduce will be closed if no activities in 3 days.

你好 @JackGuiYang12, 我们需要你提供一个在线的重现实例以便于我们帮你排查问题。你可以通过点击 此处 创建一个 codesandbox 或者提供一个最小化的 GitHub 仓库。3 天内未跟进此 issue 将会被自动关闭。

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤔 Need Reproduce We cannot reproduce your problem
Projects
None yet
Development

No branches or pull requests

3 participants