Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is slightly incorrect. It should be this.options here and on line 45 instead of prevProps.options

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would you write the if condition here?

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) {
Expand Down