diff --git a/src/index.js b/src/index.js index 66770d5..143546f 100644 --- a/src/index.js +++ b/src/index.js @@ -38,19 +38,16 @@ export default class Lottie extends React.Component { this.setAnimationControl(); } - componentWillUpdate(nextProps /* , nextState */) { - /* Recreate the animation handle if the data is changed */ - if (this.options.animationData !== nextProps.options.animationData) { - this.deRegisterEvents(this.props.eventListeners); + componentDidUpdate(prevProps) { + if (prevProps.options.animationData !== this.props.options.animationData) { + this.deRegisterEvents(prevProps.eventListeners); this.destroy(); - this.options = { ...this.options, ...nextProps.options }; + this.options = { ...prevProps.options, ...this.props.options }; this.anim = lottie.loadAnimation(this.options); this.animApi = lottieApi.createAnimationApi(this.anim); - this.registerEvents(nextProps.eventListeners); + this.registerEvents(this.props.eventListeners); } - } - - componentDidUpdate() { + if (this.props.isStopped) { this.stop(); } else if (this.props.segments) {