Skip to content

Added custom hooks to replace Timer component#2771

Merged
tdurnford merged 16 commits intomicrosoft:masterfrom
tdurnford:2313-timestamp
Jan 27, 2020
Merged

Added custom hooks to replace Timer component#2771
tdurnford merged 16 commits intomicrosoft:masterfrom
tdurnford:2313-timestamp

Conversation

@tdurnford
Copy link
Copy Markdown
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
Copy Markdown

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.

Comment thread packages/component/src/Utils/RelativeTime.js Outdated
const handleInterval = useCallback(() => {
setTimer(nextTimer(value));
}, [setTimer, value]);
useIntervalSince(value, TIMER_INTERVAL);
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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?

Comment thread packages/component/src/hooks/useIntervalSince.js
@tdurnford
Copy link
Copy Markdown
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