Skip to content

Commit

Permalink
bug: prevent crashes on hydration (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
Quicksaver authored Jun 10, 2023
1 parent 87f550f commit 0d8da68
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class FlickityComponent extends Component {
}

componentDidUpdate(prevProps, prevState) {
if (!this.flkty) return;
const {
children,
options: { draggable, initialIndex },
Expand All @@ -39,7 +40,6 @@ class FlickityComponent extends Component {
} = this.props;
const { flickityReady } = this.state;
if (reloadOnUpdate || (!prevState.flickityReady && flickityReady)) {
if (!this.flkty) return;
const isActive = this.flkty.isActive;
this.flkty.deactivate();
this.flkty.selectedIndex = initialIndex || 0;
Expand All @@ -61,7 +61,7 @@ class FlickityComponent extends Component {
}

async componentDidMount() {
if (!canUseDOM) return null;
if (!canUseDOM || !this.carousel) return null;
const Flickity = (await import('flickity')).default;
const { flickityRef, options } = this.props;
this.flkty = new Flickity(this.carousel, options);
Expand Down

0 comments on commit 0d8da68

Please sign in to comment.