From 0d8da6820033b414327e75d77dc96e3c073b1cf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Miguel?= Date: Sat, 10 Jun 2023 14:01:05 +0100 Subject: [PATCH] bug: prevent crashes on hydration (#146) --- src/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 8a180c6..61a1ac8 100644 --- a/src/index.js +++ b/src/index.js @@ -31,6 +31,7 @@ class FlickityComponent extends Component { } componentDidUpdate(prevProps, prevState) { + if (!this.flkty) return; const { children, options: { draggable, initialIndex }, @@ -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; @@ -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);