Skip to content

Commit adb66f1

Browse files
authored
Fix Bug w/ ComponentDidUpdate
1 parent 257e99b commit adb66f1

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/components/anim.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ class Anim extends Component {
3838
this.props.route.params.indexOf('overview') !== -1;
3939

4040
if (shouldDisableAnimation) {
41-
// setState in componentDidUpdate OK if wrapped in a condition according to docs
42-
// eslint-disable-next-line react/no-did-update-set-state
43-
this.setState({ activeAnimation: this.props.toStyle.length - 1 });
41+
this.disableAnimation();
4442
}
4543

4644
const animationStatus = this.getAnimationStatus();
@@ -56,15 +54,29 @@ class Anim extends Component {
5654
const forward = prevState.activeAnimation < nextAnimation;
5755
prevProps.onAnim(forward, nextAnimation);
5856
}
59-
// setState in componentDidUpdate OK if wrapped in a condition according to docs
60-
// eslint-disable-next-line react/no-did-update-set-state
61-
this.setState({
62-
activeAnimation: nextAnimation
63-
});
57+
this.updateAnimation(nextAnimation);
6458
}
6559
}
6660
}
6761

62+
disableAnimation = () => {
63+
if (this.state.activeAnimation !== this.props.toStyle.length - 1) {
64+
this.setState({ activeAnimation: this.props.toStyle.length - 1 });
65+
}
66+
67+
return;
68+
};
69+
70+
updateAnimation = nextAnimation => {
71+
if (this.state.activeAnimation !== nextAnimation) {
72+
this.setState({
73+
activeAnimation: nextAnimation
74+
});
75+
}
76+
77+
return;
78+
};
79+
6880
getAnimationStatus() {
6981
const state = this.props.fragment;
7082
const { slide } = this.props.route;

0 commit comments

Comments
 (0)