Skip to content

Commit

Permalink
update useTimer to have autoStart set to true by default
Browse files Browse the repository at this point in the history
  • Loading branch information
amrlabib committed Apr 17, 2021
1 parent 1daeeb2 commit 7af8a02
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions demo/components/UseTimerDemo.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function UseTimerDemo({ expiryTimestamp }: Object) {
pause,
resume,
restart,
} = useTimer({ expiryTimestamp, autoStart: true, onExpire: () => console.warn('onExpire called') });
} = useTimer({ expiryTimestamp, onExpire: () => console.warn('onExpire called') });

return (
<div>
Expand All @@ -28,7 +28,7 @@ export default function UseTimerDemo({ expiryTimestamp }: Object) {
// Restarts to 10 minutes timer
const time = new Date();
time.setSeconds(time.getSeconds() + 600);
restart(time, true);
restart(time);
}}
>
Restart
Expand Down
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function MyTimer({ expiryTimestamp }) {
pause,
resume,
restart,
} = useTimer({ expiryTimestamp, autoStart: true, onExpire: () => console.warn('onExpire called') });
} = useTimer({ expiryTimestamp, onExpire: () => console.warn('onExpire called') });


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


Expand Down Expand Up @@ -143,7 +143,7 @@ export default function App() {

| key | Type | Required | Description |
| --- | --- | --- | ---- |
| autoStart | boolean | No | if set to `true` stopwatch will auto start |
| autoStart | boolean | No | if set to `true` stopwatch will auto start, by default it is set to `false` |
| 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 |

### Values
Expand Down
2 changes: 1 addition & 1 deletion src/useTimer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function getDelayFromExpiryTimestamp(expiryTimestamp) {
return extraMilliSeconds > 0 ? extraMilliSeconds : DEFAULT_DELAY;
}

export default function useTimer({ expiryTimestamp: expiry, onExpire, autoStart }) {
export default function useTimer({ expiryTimestamp: expiry, onExpire, autoStart = true }) {
const [expiryTimestamp, setExpiryTimestamp] = useState(expiry);
const [seconds, setSeconds] = useState(Time.getSecondsFromExpiry(expiryTimestamp));
const [isRunning, setIsRunning] = useState(autoStart);
Expand Down

0 comments on commit 7af8a02

Please sign in to comment.