File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -14,13 +14,17 @@ export default function useTimer(settings) {
1414 }
1515 }
1616
17+ function handleExpire ( ) {
18+ clearIntervalRef ( ) ;
19+ Validate . onExpire ( onExpire ) && onExpire ( ) ;
20+ }
21+
1722 function start ( ) {
1823 if ( ! intervalRef . current ) {
1924 intervalRef . current = setInterval ( ( ) => {
2025 const secondsValue = Time . getSecondsFromExpiry ( expiryTimestamp ) ;
2126 if ( secondsValue <= 0 ) {
22- clearIntervalRef ( ) ;
23- Validate . onExpire ( onExpire ) && onExpire ( ) ;
27+ handleExpire ( ) ;
2428 }
2529 setSeconds ( secondsValue ) ;
2630 } , 1000 ) ;
@@ -33,7 +37,13 @@ export default function useTimer(settings) {
3337
3438 function resume ( ) {
3539 if ( ! intervalRef . current ) {
36- intervalRef . current = setInterval ( ( ) => setSeconds ( ( prevSeconds ) => ( prevSeconds - 1 ) ) , 1000 ) ;
40+ intervalRef . current = setInterval ( ( ) => setSeconds ( ( prevSeconds ) => {
41+ const secondsValue = prevSeconds - 1 ;
42+ if ( secondsValue <= 0 ) {
43+ handleExpire ( ) ;
44+ }
45+ return secondsValue ;
46+ } ) , 1000 ) ;
3747 }
3848 }
3949
You can’t perform that action at this time.
0 commit comments