Skip to content

Commit c462cf1

Browse files
committed
update readme file with useTimer restart function
1 parent 0e5b464 commit c462cf1

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

readme.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ React timer hook is a custom [react hook](https://reactjs.org/docs/hooks-intro.h
44

55
1. `useTimer`: Timers (countdown timer)
66
2. `useStopwatch`: Stopwatch (count up timer)
7-
3. `useTime`: Time (return current time)
7+
3. `useTime`: Time (return current time)
88

99

1010
#### Note:
@@ -39,7 +39,8 @@ function MyTimer({ expiryTimestamp }) {
3939
days,
4040
start,
4141
pause,
42-
resume
42+
resume,
43+
restart,
4344
} = useTimer({ expiryTimestamp, onExpire: () => console.warn('onExpire called') });
4445

4546

@@ -53,6 +54,12 @@ function MyTimer({ expiryTimestamp }) {
5354
<button onClick={start}>Start</button>
5455
<button onClick={pause}>Pause</button>
5556
<button onClick={resume}>Resume</button>
57+
<button onClick={() => {
58+
// Restarts to 5 minutes timer
59+
var t = new Date();
60+
t.setSeconds(t.getSeconds() + 300);
61+
restart(t)
62+
}}>restart</button>
5663
</div>
5764
);
5865
}
@@ -86,6 +93,7 @@ export default function App() {
8693
| pause | function | function to be called to pause timer |
8794
| start | function | function if called after pause the timer will continue based on original expiryTimestamp |
8895
| resume | function | function if called after pause the timer will continue countdown from last paused state |
96+
| restart | function | function to restart timer with new expiryTimestamp |
8997

9098

9199
---

0 commit comments

Comments
 (0)