Skip to content

Commit 462a55a

Browse files
author
yeewong
committed
fix: add alesanderlopez's fix
Kerumen#9
1 parent 5d951bb commit 462a55a

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/Counter.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,23 @@ export default class Counter extends Component {
2525

2626
componentDidMount() {
2727
this.startTime = Date.now();
28+
this.umount = false
29+
requestAnimationFrame(this.animate.bind(this));
30+
}
31+
32+
componentWillUnmount() {
33+
this.umount = true
34+
}
35+
36+
reset() {
37+
this.startTime = Date.now();
38+
this.stop = false
2839
requestAnimationFrame(this.animate.bind(this));
2940
}
3041

3142
animate() {
43+
if (this.umount) return;
44+
3245
const { onComplete } = this.props;
3346

3447
if (this.stop) {
@@ -60,4 +73,4 @@ export default class Counter extends Component {
6073
<Text style={style}>{value.toFixed(digits)}</Text>
6174
);
6275
}
63-
}
76+
}

0 commit comments

Comments
 (0)