You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* support milliseconds in useTimer
* update readme of useTimer settings and returned values
* support milliseconds in useStopwatch
* support milliseconds in useTime
* handle milliseconds precision in useTimer after pause and resume
* handle milliseconds precision in useStopwatch after pause and start
* move intervals to constants
* update types
* update readme file
* conditionally increment precision counter
* update readme file
* update milliseconds interval to 20ms
* replace enableMilliseconds with custom interval
* validate
* useStopwatch accurate pause and resume
* remove passed seconds state from useStopwatch
* update readme
Copy file name to clipboardExpand all lines: demo/App.js
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -66,11 +66,11 @@ export default function App() {
66
66
<p>
67
67
React timer hook is a custom <ahref="https://reactjs.org/docs/hooks-intro.html"target="_blank">react hook</a> built to handle timer, stopwatch, and time logic/state in your react component.
@@ -75,18 +76,21 @@ export default function App() {
75
76
| --- | --- | --- | ---- |
76
77
| expiryTimestamp | Date object | YES | this will define for how long the timer will be running |
77
78
| autoStart | boolean | No | flag to decide if timer should start automatically, by default it is set to `true`|
79
+
| interval | number | No | value to change the interval of the timer, by default it is set to 1000ms. Note: this value will not affect the timer, it will just define the frequency used to calculate the current timer values. For example, if you have a use case where milliseconds are used, you need to use a smaller value for the interval, for example, 20ms or 100ms based on your needs. |
78
80
| onExpire | Function | No | callback function to be executed once countdown timer is expired |
79
81
80
82
81
83
### Values
82
84
83
85
| key | Type | Description |
84
86
| --- | --- | ---- |
87
+
| milliseconds | number | milliseconds value, to get accurate ms values you need to set interval to a smaller value example: 20ms |
85
88
| seconds | number | seconds value |
86
89
| minutes | number | minutes value |
87
90
| hours | number | hours value |
88
91
| days | number | days value |
89
92
| totalSeconds | number | total number of seconds left in timer NOT converted to minutes, hours or days |
93
+
| totalMilliseconds | number | total number of milliseconds left in timer NOT converted to minutes, hours or days |
90
94
| isRunning | boolean | flag to indicate if timer is running or not |
91
95
| pause | function | function to be called to pause timer |
92
96
| start | function | function if called after pause the timer will continue based on original expiryTimestamp |
@@ -107,6 +111,7 @@ import { useStopwatch } from 'react-timer-hook';
@@ -148,11 +153,13 @@ export default function App() {
148
153
| --- | --- | --- | ---- |
149
154
| autoStart | boolean | No | if set to `true` stopwatch will auto start, by default it is set to `false`|
150
155
| offsetTimestamp | Date object | 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 |
156
+
| interval | number | No | value to change the interval of the stopwatch, by default it is set to 1000ms. Note: this value will not affect the stopwatch, it will just define the frequency used to calculate the current timer values. For example, if you have a use case where milliseconds are used, you need to use a smaller value for the interval, for example, 20ms or 100ms based on your needs. |
151
157
152
158
### Values
153
159
154
160
| key | Type | Description |
155
161
| --- | --- | ---- |
162
+
| milliseconds | number | milliseconds value, to get accurate ms values you need to set interval to a smaller value example: 20ms |
156
163
| seconds | number | seconds value |
157
164
| minutes | number | minutes value |
158
165
| hours | number | hours value |
@@ -177,18 +184,19 @@ import { useTime } from 'react-timer-hook';
@@ -208,11 +216,13 @@ export default function App() {
208
216
| key | Type | Required | Description |
209
217
| --- | --- | --- | ---- |
210
218
| format | string | No | if set to `12-hour` time will be formatted with am/pm |
219
+
| interval | number | No | value to change the interval of the time, by default it is set to 1000ms. Note: this value will not affect the thime, it will just define the frequency used to calculate the current time values. For example, if you have a use case where milliseconds are used, you need to use a smaller value for the interval, for example, 20ms or 100ms based on your needs. |
0 commit comments