-
Notifications
You must be signed in to change notification settings - Fork 305
feat(@toss/react): useInterval stop/resume support #476
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
Conversation
@d0422 is attempting to deploy a commit to the Toss Team on Vercel. A member of the Team first needs to authorize it. |
Hello, thanks for your contribution! While this change helps the use of However, I think adding an What do you think? |
@raon0211 type IntervalOptions =
| number
| {
delay: number | null;
trailing?: boolean;
enabled?: boolean;
}; |
} | ||
|
||
const id = window.setInterval(tick, delay); | ||
return () => window.clearInterval(id); | ||
}, [delay, savedCallback]); | ||
}, [delay, savedCallback, enabled]); |
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.
I think it would be better for us if we did not register a callback at all if it is not enabled like the following code.
useEffect(() => {
if (delay == null || !enabled) {
return;
}
const id = window.setInterval(tick, delay);
return () => window.clearInterval(id);
}, [delay, savedCallback, enabled]);
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.
Thank you for your feedback. I have reflected your opinion and added the corresponding test code.
Overview
When using Interval, sometimes you need to stop and resume the interval.
When configuring the carousel, if auto-turning is implemented through useInterval, the interval must be stopped when the user is in the middle of the slide, and the interval must be resumed when the slide is completed.
In this case, I suggest that if it returns the factors presented above in the hook, it will be easy to implement!
Accordingly, why don't you return the stop, resume function, and intervalRunning status.
PR Checklist