-
Notifications
You must be signed in to change notification settings - Fork 622
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
feat: add useInterval and useTimeout #1462
Conversation
|
||
function clearTimer(id) { | ||
if (id != null) clearInterval(id); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
其实这里可以不用判断, clearInterval 接受任何类型都不会抛出异常
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 逻辑上正确 2. clearInterval 还是比较重的行为
import { useEffect, useRef } from 'rax'; | ||
|
||
function clearTimer(id) { | ||
if (id != null) clearTimeout(id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
其它没有问题
Why
useInterval
?setInterval
will called even component is unmounted that make error happens, anduseInterval
will autoclearInterval
before component will mount.