Skip to content

Commit

Permalink
⚡ Opatimize badge code
Browse files Browse the repository at this point in the history
  • Loading branch information
afc163 committed Mar 11, 2019
1 parent 9f45468 commit f694a1b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions components/badge/ScrollNumber.tsx
Expand Up @@ -42,7 +42,10 @@ class ScrollNumber extends Component<ScrollNumberProps, ScrollNumberState> {
if (nextState.count === nextProps.count) {
return null;
}
return { animateStarted: true };
return {
animateStarted: true,
count: nextProps.count,
};
}
return null;
}
Expand Down Expand Up @@ -78,9 +81,10 @@ class ScrollNumber extends Component<ScrollNumberProps, ScrollNumberState> {

componentDidUpdate(_: any, prevState: ScrollNumberState) {
this.lastCount = prevState.count;
if (this.state.animateStarted) {
this.setState({ animateStarted: false, count: this.props.count }, () => {
const { onAnimated } = this.props;
const { animateStarted } = this.state;
const { onAnimated } = this.props;
if (animateStarted) {
this.setState({ animateStarted: !animateStarted }, () => {
if (onAnimated) {
onAnimated();
}
Expand Down

0 comments on commit f694a1b

Please sign in to comment.