Skip to content

Instantly share code, notes, and snippets.

@JoshBarr
Last active January 20, 2019 23:21
Show Gist options
  • Select an option

  • Save JoshBarr/f302ebf7f43ea596ad6a to your computer and use it in GitHub Desktop.

Select an option

Save JoshBarr/f302ebf7f43ea596ad6a to your computer and use it in GitHub Desktop.
Flickity React integration
@YarivGilad
Copy link
Copy Markdown

Hi!
Thank you for sharing!
I'm trying to use this integration in an isomorphic app which renders react also on the server and get the following error:

\node_modules\flickity\js\index.js:40
})( window, function factory( Flickity ) {
    ^
ReferenceError: window is not defined

Do you have any idea how to solve this issue?
Cheers
Ajar

@benbonnet
Copy link
Copy Markdown

benbonnet commented May 12, 2016

@Ajar-Ajar window does not exists on server-side (initially)

@irisSchaffer
Copy link
Copy Markdown

If you want to get around this, you'll have to require() flickity, where you need it, rather than importing it :)

@cengizdemir
Copy link
Copy Markdown

Use this;
Helper:
export function onlyClient(callback) {
if (typeof window !== 'undefined') {
callback();
}
}

Using: onlyClient(() => {
....
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment