Comments (22)
OK! Thanks for opening this issue. I'll let you have a look on PR.
from use-timer.
I'm writing "use-timer": "thibaultboursier/use-timer#fix-start-function-reference-issue"
in dependencies list. It is downloading without any problem, but project is not starting after that.
from use-timer.
Hello @dancheskus,
Thanks for opening issue.
It's better if you provide me a reproductible issue, on StackBlitz for example.
I created an example: https://stackblitz.com/edit/use-timer-issue-47?file=index.tsx
Inside, we have a useEffect
, for the autostart purpose, which has start
function inside its dependencies array.
When we click on increment button, component is re-rendered, but timer does not start a new time.
I need more informations.
from use-timer.
Timer should be decremental
to see this bug. There also should be endTime
.
https://stackblitz.com/edit/use-timer-issue-47-pfnhg7?file=index.tsx
from use-timer.
I see. There should be some issue with start
function reference, which causes a re-render as you declared it inside dependencies array. I'm going to investigate. Anyway, if you want to be sure that start
function is executed only once, you should remove start
function from dependencies array; it works.
const { time, start, pause, reset, isRunning } = useTimer({
initialTime: 3,
endTime: 0,
timerType: "DECREMENTAL"
});
useEffect(()=>{
start();
}, [])
from use-timer.
I know it will work without start function in dependencies array. But it should be there according to React rules.
Maybe it could be a good thing to add as a prop in timer settings, like
const { time, start, pause, reset, isRunning } = useTimer({
autostart: true // default: false
});
from use-timer.
It's a good idea to add autostart
feature.
I don't think it's an issue to have an empty dependency array: that way, you are sure to enter inside just once. More and more you fill it, and more and more you must rely on external dependencies (in our case, my library), for which functions identity could not be stable and cause some re-renders.
from use-timer.
If you’ll add autostart
feature, there should also be an option to disable or enable it when component is already working. For example:
- Component mounted
- Timer starts
- Timer finished
- User clicks “reset timer“...
What will be next? Timer will start again by default? Maybe after resetting timer I want to disable autostart.
from use-timer.
In my opinion, since the timer has been auto-started once, it should not be auto-started again by default, after a reset for example.
from use-timer.
Fair enough
from use-timer.
You want to make a PR for this auto-start feature? I you don't, i could make it quickly tonight.
from use-timer.
I think you will do it faster 😊
from use-timer.
Hello @dancheskus ,
I made two PR:
Please, have a look on it. If it's OK for you, I will include it inside release 2.0.0
and will close this issue.
from use-timer.
Thanks, I will check it today. The only thing I don't know how to test it with my React project. How can I download not master use-timer
package but another branch?
from use-timer.
If you select develop
branch, for example (https://github.com/thibaultboursier/use-timer/tree/develop), and you download zip, you will have use-timer-develop.zip
.
But i suppose you talk about NPM download? You can do that:
"dependencies": {
"use-timer": "thibaultboursier/use-timer#develop"
}
from use-timer.
It should work with my PR branches ;-)
from use-timer.
Do you have some errors?
from use-timer.
Do you have some errors?
step by step.
yarn remove use-timer
yarn add thibaultboursier/use-timer#fix-start-function-reference-issue
- result in dependencies:
"dependencies": {
"use-timer": "thibaultboursier/use-timer#fix-start-function-reference-issue"
},
yarn start
- error:
Failed to compile.
./src/components/MyComponent.js
Module not found: Can't resolve 'use-timer' in 'E:\Desktop\MyProj\src\components\MyComponent'
from use-timer.
I'm going to test on my side.
from use-timer.
Download module has empty source.
If you want to find a fasted solution, maybe you can copy library code inside your project (if you are in TypeScript) to test it. I'll find a solution to have an elegant way to test branches.
from use-timer.
#48 looks good. Just waiting for variable rename
from use-timer.
Fixed by PR #50.
from use-timer.
Related Issues (14)
- Add Prettier to project
- `setTime` from the `useTimer` hook? HOT 6
- Milliseconds timer with endTime HOT 5
- Would you consider a PR that adds a third state for the timer? HOT 7
- Missing payload. HOT 6
- Changing default endTime value if mode is "Decremental" HOT 1
- Timer callbacks
- timer not accurate in mobile HOT 1
- problem with firefox browser HOT 10
- Feature request: set initial status HOT 6
- Updating initial time won't update the timer HOT 7
- wrong time over calculation
- Consider using Milliseconds instead of seconds HOT 1
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 use-timer.