Skip to content

Commit 8018222

Browse files
committed
set autoStart to true by default in both restart and reset
1 parent 03a181c commit 8018222

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export default function App() {
8989
| pause | function | function to be called to pause timer |
9090
| start | function | function if called after pause the timer will continue based on original expiryTimestamp |
9191
| resume | function | function if called after pause the timer will continue countdown from last paused state |
92-
| restart | function | function to restart timer with new expiryTimestamp, accept 2 arguments first is the new `expiryTimestamp` of type number(timestamp) and second is `autoStart` of type boolean to decide if it should automatically start after restart or not |
92+
| restart | function | function to restart timer with new expiryTimestamp, accept 2 arguments first is the new `expiryTimestamp` of type number(timestamp) and second is `autoStart` of type boolean to decide if it should automatically start after restart or not, default is `true` |
9393

9494

9595
---
@@ -157,7 +157,7 @@ export default function App() {
157157
| isRunning | boolean | flag to indicate if stopwatch is running or not |
158158
| start | function | function to be called to start/resume stopwatch |
159159
| pause | function | function to be called to pause stopwatch |
160-
| reset | function | function to be called to reset stopwatch to 0:0:0:0, you can also pass offset parameter to this function to reset stopwatch with offset, similar to how `offsetTimestamp` will offset the initial stopwatch time |
160+
| reset | function | function to be called to reset stopwatch to 0:0:0:0, you can also pass offset parameter to this function to reset stopwatch with offset, similar to how `offsetTimestamp` will offset the initial stopwatch time, this function will accept also a second argument which will decide if stopwatch should automatically start after reset or not default is `true` |
161161

162162

163163
---

src/useStopwatch.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ export default function useStopwatch({ autoStart, offsetTimestamp }) {
1818
setIsRunning(false);
1919
}
2020

21-
function reset(offset: number) {
22-
setIsRunning(autoStart);
23-
setSeconds(Time.getSecondsFromExpiry(offset || 0));
21+
function reset(offset = 0, newAutoStart = true) {
22+
setIsRunning(newAutoStart);
23+
setSeconds(Time.getSecondsFromExpiry(offset));
2424
}
2525

2626
return {

src/useTimer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default function useTimer({ expiryTimestamp: expiry, onExpire, autoStart
2121
setIsRunning(false);
2222
}
2323

24-
function restart(newExpiryTimestamp, newAutoStart) {
24+
function restart(newExpiryTimestamp, newAutoStart = true) {
2525
const secondsValue = Time.getSecondsFromExpiry(newExpiryTimestamp);
2626
const extraMilliSecondsValue = Math.floor((secondsValue - Math.floor(secondsValue)) * 1000);
2727
setDelay(extraMilliSecondsValue > 0 ? extraMilliSecondsValue : 1000);

0 commit comments

Comments
 (0)