Skip to content

Commit 7af8a02

Browse files
committed
update useTimer to have autoStart set to true by default
1 parent 1daeeb2 commit 7af8a02

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

demo/components/UseTimerDemo.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default function UseTimerDemo({ expiryTimestamp }: Object) {
1313
pause,
1414
resume,
1515
restart,
16-
} = useTimer({ expiryTimestamp, autoStart: true, onExpire: () => console.warn('onExpire called') });
16+
} = useTimer({ expiryTimestamp, onExpire: () => console.warn('onExpire called') });
1717

1818
return (
1919
<div>
@@ -28,7 +28,7 @@ export default function UseTimerDemo({ expiryTimestamp }: Object) {
2828
// Restarts to 10 minutes timer
2929
const time = new Date();
3030
time.setSeconds(time.getSeconds() + 600);
31-
restart(time, true);
31+
restart(time);
3232
}}
3333
>
3434
Restart

readme.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function MyTimer({ expiryTimestamp }) {
3333
pause,
3434
resume,
3535
restart,
36-
} = useTimer({ expiryTimestamp, autoStart: true, onExpire: () => console.warn('onExpire called') });
36+
} = useTimer({ expiryTimestamp, onExpire: () => console.warn('onExpire called') });
3737

3838

3939
return (
@@ -73,7 +73,7 @@ export default function App() {
7373
| key | Type | Required | Description |
7474
| --- | --- | --- | ---- |
7575
| expiryTimestamp | number(timestamp) | YES | this will define for how long the timer will be running |
76-
| autoStart | boolean | No | flag to decide if timer should start automatically |
76+
| autoStart | boolean | No | flag to decide if timer should start automatically, by default it is set to `true` |
7777
| onExpire | Function | No | callback function to be executed once countdown timer is expired |
7878

7979

@@ -143,7 +143,7 @@ export default function App() {
143143

144144
| key | Type | Required | Description |
145145
| --- | --- | --- | ---- |
146-
| autoStart | boolean | No | if set to `true` stopwatch will auto start |
146+
| autoStart | boolean | No | if set to `true` stopwatch will auto start, by default it is set to `false` |
147147
| offsetTimestamp | number | No | this will define the initial stopwatch offset example: `const stopwatchOffset = new Date(); stopwatchOffset.setSeconds(stopwatchOffset.getSeconds() + 300);` this will result in a 5 minutes offset and stopwatch will start from 0:0:5:0 instead of 0:0:0:0 |
148148

149149
### Values

src/useTimer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function getDelayFromExpiryTimestamp(expiryTimestamp) {
1313
return extraMilliSeconds > 0 ? extraMilliSeconds : DEFAULT_DELAY;
1414
}
1515

16-
export default function useTimer({ expiryTimestamp: expiry, onExpire, autoStart }) {
16+
export default function useTimer({ expiryTimestamp: expiry, onExpire, autoStart = true }) {
1717
const [expiryTimestamp, setExpiryTimestamp] = useState(expiry);
1818
const [seconds, setSeconds] = useState(Time.getSecondsFromExpiry(expiryTimestamp));
1919
const [isRunning, setIsRunning] = useState(autoStart);

0 commit comments

Comments
 (0)