Comments (5)
Hi @amrlabib , no, its not that. I'll try to give you a concrete example:
If you try to run a task in 1.5 seconds from now, it will actually run in 1 second from now.
If you try to run a task in 500 milliseconds it will run in 1 second.
That's because the min interval in which tasks are checked is fixed in 1000ms (1 sec). So, any task that needs to run in a not rounded number of seconds will not get executed in the correct moment.
If you accept a custom parameter for the min interval, it will work, however there's more things that might need to change because some places assumes the number of seconds is round (or it gets rounded/floored).
I would say that the goal here would be to make it possible to run timers in intervals less than a second (100ms, 300ms, 500ms) accurately.
Does that makes sense?
from react-timer-hook.
Hi @rafmsou thank you for the issue, trying to understand your use case what do you mean by run a timer in 1.5 seconds ? you want to change the default interval from 1000ms (1s) to be 1500 (1.5s) ?
we can pass a custom param to change the default interval but just to confirm, this means that if the custom interval is 1.5s a 1 minute timer will run for (1.5s * 60) = 90s is this what you are trying to achieve ?
from react-timer-hook.
Could we get milliseconds from the hook with minimal modification? That would solve the problem.
A "throttle" prop would be awesome though
from react-timer-hook.
Sorry for the late response, i updated the code of useTimer
to handle milliseconds
Example: 1
if expiryTimeStamp
will result in a 3.4 seconds [3400 ms] timer, it will behave as mentioned below:
interval | values |
---|---|
now | 00:00:04 |
after 400 ms | 00:00:03 |
after 1000 ms | 00:00:02 |
after 1000 ms | 00:00:01 |
after 1000 ms | 00:00:00 |
Example: 2
if expiryTimeStamp
will result in a 0.6 seconds [600 ms] timer, it will behave as mentioned below:
interval | values |
---|---|
now | 00:00:01 |
after 600 ms | 00:00:00 |
This is handled in v2.0.5, let me know if this is working well, and thank you again for reporting the issue
from react-timer-hook.
Haha I have a similar request, except that I'd love to be able to get sub-seconds (milliseconds) from useStopwatch! Maybe by specifying an update interval...?
Happy to make a PR, just checking if you already know a quick change or any gotchas before I try my hand!
from react-timer-hook.
Related Issues (20)
- Is there a way to manually set the time in useStopwatch?
- Just a question HOT 1
- useStopwatch not working HOT 1
- useStopwatch hook is causing continuous rerender HOT 2
- useStopwatch reset with offsetTimestamp always restarts at 0 HOT 2
- restart Function not working as Expected HOT 11
- Handling multiple timers
- multiple onExpire calls when the function is asynchronous HOT 2
- Is it possible to integrate intervals that have sound in the timer?
- Please support UTC time
- Start function in UseStopwatch Demo not working as Expected HOT 1
- Unnecessary re-rendering HOT 1
- Does this handle on focus window? HOT 1
- react native install issues HOT 1
- useStopwatch and useTime args are required HOT 1
- Please support returning miliseconds HOT 9
- How to get the current time on any event? HOT 1
- useTimer pause issue. HOT 1
- How to set useTimer to get seconds upper than 60s, HOT 1
- TS error Property 'totalSeconds' does not exist on type 'StopwatchResult' HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-timer-hook.