-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Added custom hooks to replace Timer component #2771
Conversation
const handleInterval = useCallback(() => { | ||
setTimer(nextTimer(value)); | ||
}, [setTimer, value]); | ||
useIntervalSince(value, TIMER_INTERVAL); |
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.
No callback function for useIntervalSince
?
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.
If we don't change the useState
hook to useRef
in useIntervalSince
, then setting the timer
would rerender the component; otherwise, we would have to add a forceRender
state hook to create a callback and rerender the timestamp.
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 am thinking about the hook design perspective, not about refactoring.
- If we name it
useForceRenderAtInterval
, it works for me. - After starting the interval timer, how to stop it?
@compulim ping |
Fixes #2313
Changelog Entry
useTimer
anduseIntervalSince
- to replaceTimer
component, by @tdurnford, in PR #2771Description
useTimer
anduseIntervalSince
hooksTimer
component from theRelativeTime
component