Skip to content

Commit e327de5

Browse files
committed
fix: update clock when change initialSeconds
1 parent e816a56 commit e327de5

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/CountDown/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ const CountdownComponent = React.forwardRef<any, CountDownProps>(
5353
minute.current = ~~((currentSeconds.current % 3600) / 60);
5454
seconds.current = ~~currentSeconds.current % 60;
5555
}
56-
clear();
5756
setKey(Math.random());
5857
}, [initialSeconds]);
5958

@@ -79,12 +78,13 @@ const CountdownComponent = React.forwardRef<any, CountDownProps>(
7978
clear();
8079
};
8180

82-
useEffect(() => {
81+
useEffect(()=>{
8382
init();
83+
}, [initialSeconds]);
8484

85+
useEffect(() => {
8586
return () => {
8687
pause();
87-
init();
8888
};
8989
}, []);
9090

src/Timer/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ const TimerComponent = React.forwardRef<any, TimerProps>((props, ref) => {
9191
initTime(initialSeconds);
9292
}
9393

94-
clear();
9594
setKey(Math.random());
9695
}, [initialSeconds]);
9796

@@ -135,9 +134,11 @@ const TimerComponent = React.forwardRef<any, TimerProps>((props, ref) => {
135134

136135
useEffect(() => {
137136
init();
137+
}, [initialSeconds]);
138+
139+
useEffect(() => {
138140
return () => {
139141
pause();
140-
init();
141142
};
142143
}, []);
143144

0 commit comments

Comments
 (0)