Skip to content

Commit 9333af5

Browse files
author
Hoa Phan
committed
chore: clean code
1 parent ed2f0ae commit 9333af5

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

src/CountDown/index.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ const CountdownComponent = React.forwardRef<any, CountDownProps>(
8888
};
8989
}, []);
9090

91+
useEffect(() => {
92+
if (autoStart) {
93+
start();
94+
}
95+
}, [autoStart]);
96+
9197
const timer = useCallback(() => {
9298
interval.current = BackgroundTimer.setInterval(() => {
9399
if (currentSeconds.current > 0) {
@@ -118,12 +124,6 @@ const CountdownComponent = React.forwardRef<any, CountDownProps>(
118124
}
119125
}, []);
120126

121-
useEffect(() => {
122-
if (autoStart) {
123-
start();
124-
}
125-
}, [autoStart]);
126-
127127
const clear = () => {
128128
if (interval.current) {
129129
BackgroundTimer.clearInterval(interval.current);

src/Timer/index.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,25 +134,18 @@ const TimerComponent = React.forwardRef<any, TimerProps>((props, ref) => {
134134
};
135135

136136
useEffect(() => {
137+
init();
137138
return () => {
138139
pause();
139140
init();
140-
setKey(Math.random());
141141
};
142142
}, []);
143143

144-
useEffect(() => {
145-
if (initialSeconds > 0) {
146-
init();
147-
}
148-
setKey(Math.random());
149-
}, [init, initialSeconds]);
150-
151144
useEffect(() => {
152145
if (autoStart) {
153146
start();
154147
}
155-
}, [autoStart, initialSeconds, start]);
148+
}, [autoStart]);
156149

157150
const font = () => {
158151
if (fontFamily) {

0 commit comments

Comments
 (0)