diff --git a/src/animate.js b/src/animate.js index 1b83803..131c897 100644 --- a/src/animate.js +++ b/src/animate.js @@ -52,6 +52,19 @@ export class AnimateChild extends React.PureComponent { 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, @@ -60,21 +73,12 @@ export class AnimateChild extends React.PureComponent { }; 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) {