-
Notifications
You must be signed in to change notification settings - Fork 164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[287] fix undefined window #292
Conversation
b677fdd
to
c0bed08
Compare
I'm in a Gatsby environment as well and introducing window to the global state in this way will actually conflict with other plugins that check to see if window is defined. I believe a better way would be to truly check to see if window is defined in the component itself. For example, in Carousel.js
|
Thanks for your comment. |
For anyone looking for quick workaround, that's what I have done to use react-carousel with SSR, without Next.js:
function isBrowser() {
return typeof window !== "undefined";
}
class MySuperSlider extends React.Component {
constructor(props) {
super(props);
if (isBrowser()) {
this.Carousel = require("@brainhubeu/react-carousel").default;
this.Dots = require("@brainhubeu/react-carousel").Dots;
}
}
render() {
if (!isBrowser()) {
return null;
}
const { Carousel, Dots } = this.
// Do stuff using <Carousel> and <Dots>
// just like you would with regular import
}
} I do realize that this solution is far from elegant, but it gets the job done, and is easier than migrating whole project to Next.js :) |
Simple approach that's inline with how things were working prior to the webpack v4 upgrade on PR #344 |
Deployed to https://beghp.github.io/gh-pages-rc-6
- [x]
package.json:version
has been updated withnpm version patch
(ormajor/minor
as appropriate)- [ ]
@brainhubeu/react-carousel
version has been updated indocs-www/package.json
to the same which is inpackage.json:version