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

Added custom hooks to replace Timer component #2771

Merged
merged 16 commits into from
Jan 27, 2020

Conversation

tdurnford
Copy link
Contributor

@tdurnford tdurnford commented Dec 23, 2019

Fixes #2313

Changelog Entry

  • Added custom hooks - useTimer and useIntervalSince - to replace Timer component, by @tdurnford, in PR #2771

Description

  • Added useTimer and useIntervalSince hooks
  • Removed Timer component from the RelativeTime component

  • Testing Added

@coveralls
Copy link

coveralls commented Dec 23, 2019

Coverage Status

Coverage increased (+0.2%) to 66.081% when pulling 3700c6a on tdurnford:2313-timestamp into 04fe2c3 on microsoft:master.

packages/component/src/Utils/RelativeTime.js Outdated Show resolved Hide resolved
const handleInterval = useCallback(() => {
setTimer(nextTimer(value));
}, [setTimer, value]);
useIntervalSince(value, TIMER_INTERVAL);
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

  1. If we name it useForceRenderAtInterval, it works for me.
  2. After starting the interval timer, how to stop it?

packages/component/src/hooks/useIntervalSince.js Outdated Show resolved Hide resolved
@tdurnford
Copy link
Contributor Author

@compulim ping

@tdurnford tdurnford merged commit 38a2c78 into microsoft:master Jan 27, 2020
@compulim compulim mentioned this pull request Mar 5, 2020
40 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom use hooks to replace <Timer>
3 participants