alibaba / alibaba/hooks

[RFC] useTimer

Open
#2,625 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
TypeScript
Stars
15k
Forks
2.8k
Avg merge
15h 7m
Merged PRs (30d)
2

Description

针对时间管理的一些方法,如倒计时和计时器。将关于时间的操作统一收敛到一个hooks里面。例如,可以毫无心智负担地去做倒计时功能,从而在此基础上去完善其业务逻辑,业务逻辑不用包含过多的倒计时功能
### API
```
const returnValue= useTimer(
time: number | Date,
options: Options,
deps: DependencyList = [],
):ReturnValue;
```
### Demo
```
const { seconds, minutes, hours, days, start, pause, reset, isPaused } = useTimer(
1000 * 3,
{
onComplete: () => {
Message.info('计时完成');
},
auto: false
},
);

return (
<>
{isPaused && 暂停中}


{days ? {days}天 : null}

{hours}:{minutes}:{seconds}


start()}>
开始/恢复

pause()}>
暂停

reset()}>
复位


);
```
pr https://github.com/alibaba/hooks/pull/2626

Contributor guide

Open the contributing guide

Research direction

Start with the proposed useTimer API and demo in this issue, then review the linked PR #2626 to understand the work already underway. Done means the timer and countdown behavior, controls, pause state, reset behavior, and completion callback match the documented API and demo.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
15/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.