juvenpajares / react-flickity

8 stars 6 forks source link

React (isomorphic server side) integration - ReferenceError: window is not defined #3

Open YarivGilad opened 8 years ago

YarivGilad commented 8 years ago

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? Does this suppose to work with server side rendering at all? Cheers Ajar

thomasmaclean commented 8 years ago

You can only instantiate this plugin on the client. You'll have to do something like the following: componentDidMount() { if (__CLIENT__) { ReactFlickity = require('react-flickity'); flickity = require('flickity'); } } ...and then maybe set a state variable to indicate you've initialized the plugin.