Skip to content

Commit 0d8da68

Browse files
authored
bug: prevent crashes on hydration (#146)
1 parent 87f550f commit 0d8da68

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class FlickityComponent extends Component {
3131
}
3232

3333
componentDidUpdate(prevProps, prevState) {
34+
if (!this.flkty) return;
3435
const {
3536
children,
3637
options: { draggable, initialIndex },
@@ -39,7 +40,6 @@ class FlickityComponent extends Component {
3940
} = this.props;
4041
const { flickityReady } = this.state;
4142
if (reloadOnUpdate || (!prevState.flickityReady && flickityReady)) {
42-
if (!this.flkty) return;
4343
const isActive = this.flkty.isActive;
4444
this.flkty.deactivate();
4545
this.flkty.selectedIndex = initialIndex || 0;
@@ -61,7 +61,7 @@ class FlickityComponent extends Component {
6161
}
6262

6363
async componentDidMount() {
64-
if (!canUseDOM) return null;
64+
if (!canUseDOM || !this.carousel) return null;
6565
const Flickity = (await import('flickity')).default;
6666
const { flickityRef, options } = this.props;
6767
this.flkty = new Flickity(this.carousel, options);

0 commit comments

Comments
 (0)