Skip to content

Commit

Permalink
move the logic into construtor
Browse files Browse the repository at this point in the history
  • Loading branch information
bluebill1049 committed Oct 16, 2018
1 parent 8a020f9 commit 8a21abc
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/animate.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ export class AnimateChild extends React.PureComponent<Props, State> {
easeType: 'linear',
};

constructor(props: Props) {
super(props);

if (props.play) {
this.isMountWithPlay = true;

setTimeout(() => {
this.isMountWithPlay = false;
this.forceUpdate();
}, (props.delaySeconds || 0) * 1000);
}
}

state: State = {
willComplete: false,
play: false,
Expand All @@ -60,21 +73,12 @@ export class AnimateChild extends React.PureComponent<Props, State> {
};

componentDidMount() {
const { register, mount, play, delaySeconds = 0 } = this.props;
const { register, mount } = this.props;
register && register(this.props);

if (mount && !this.state.shouldMount) {
this.mountTimeout = setTimeout(() => this.setState({ shouldMount: true }));
}

if (play) {
this.isMountWithPlay = true;

setTimeout(() => {
this.isMountWithPlay = false;
this.forceUpdate();
}, delaySeconds * 1000);
}
}

static getDerivedStateFromProps(nextProps: Props, prevState: State) {
Expand Down

0 comments on commit 8a21abc

Please sign in to comment.