Skip to content

Commit c145d97

Browse files
committed
handle autoStart in useStopwatch and replace old stop calls with reset for unmount
1 parent 97a77fe commit c145d97

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/useTimer.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,10 @@ export function useStopwatch(settings) {
9191

9292
// didMount effect
9393
useEffect(() => {
94-
start();
95-
return stop;
94+
if(autoStart) {
95+
start();
96+
}
97+
return reset;
9698
},[]);
9799

98100
return { seconds, minutes, hours, days, start, pause, reset };
@@ -161,7 +163,7 @@ export function useTimer(settings) {
161163
// didMount effect
162164
useEffect(() => {
163165
start();
164-
return stop;
166+
return reset;
165167
},[]);
166168

167169

0 commit comments

Comments
 (0)