-
Notifications
You must be signed in to change notification settings - Fork 51
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
Component breaks SSR #4
Comments
Closing this in favour of #5 |
For anyone that needs, I was able to get SSR working with something like the following (Gatsby example): class Testimonials extends Component {
state = { Flickity: null };
constructor(props) {
super(props);
if (typeof window !== 'undefined') {
const Flickity = require('react-flickity-component');
this.state.Flickity = Flickity;
}
}
render() {
const { Flickity } = this.state;
const { data: { testimonials } } = this.props;
return (
<section className="text-center imagebg" data-overlay="8">
<div className="background-image-holder">
<img alt="background" src={bgImage} />
</div>
<div className="container">
<div className="row">
<div className="col-lg-8 col-md-10">
<div className="slider">
{Flickity && (
<Flickity
className={'slides'}
elementType={'ul'}
options={{
wrapAround: true,
autoPlay: true,
draggable: true,
pageDots: false,
prevNextButtons: false,
}}>
{testimonials.edges.map(({ node }) => (
<li key={node.id}>
<div className="testimonial">
<blockquote>{node.frontmatter.quote}</blockquote>
<h5>{node.frontmatter.title}</h5>
<span className="type--fade">
{node.frontmatter.location}
</span>
</div>
</li>
))}
</Flickity>
)}
</div>
</div>
</div>
</div>
</section>
);
}
} |
I'm using this in the import and works:
|
Use this above your component. |
Hey @kierangillen , I've just stumbled across your answer. I've got the same problem re. window error. Are you adding this directly below the imports? And are you excluding Thanks |
When trying to render this on the server I get -
The text was updated successfully, but these errors were encountered: