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
Problem in rendering Slider with dynamic children #504
Comments
Can you reproduce the issue with this jsfiddle and provide link |
Sure. Here's the implementation of my described problem: https://jsfiddle.net/8qLhy7do/1/ If options |
Hey chochihim, it looks like you're not try:
|
+1 Having this issue too. On version 0.14.5 for react-slick. |
+1 |
version 15.3.2 Cannot read property 'getBoundingClientRect' of null |
+1 same here. basically this line fails |
@hackhat I had exactly the same issue and fixed by adding <Slider {...settings}>
{slides.map((slide, index) => (
<div data-index={index} key={index}>{index}</div>
))}
</Slider> I've just started adding this library to my project, so I'm not sure if it won't cause some other issues later on. |
@szimek That's the same thing I did, but something doesn't feel right about it. |
@hackhat you can try this: |
@ShuaiShuaiguo You mean removing the
|
Which version of react-slick are you using ? I don't see this issue with latest release. |
@akiran I got the issue with |
@hackhat Can provide a jsfiddle to replicate your issue ? |
@akiran I was able to reproduce the issue here: https://jsfiddle.net/17xt8pxw/2/ It seems like if we start out with no children (e.g. this.state.slides = []), then there is a problem. When there is at least one children before the initialization of the slick slider (e.g. this.state.slides = [1]), then it still works. Edit: |
@hackhat |
+1 This is definitely a bug with 14.5. I pretty much have the same set up as the OP but utilizing a Redux store. My store initializes as empty then is populated later. React-slick shouldn't even be initializing with an empty array. |
@samplefrequency Agreed. I will try to fix it soon |
+1, setting manually |
@andricicezar Still won't fix the issue if the array starts off empty and is later populated via AJAX or from a Redux store. |
Still not working :/ |
As a quick workaround, you can mount slider only if you have slides.
|
@akiran I solve this problem almost like you: Thanks for react-slick! |
@akiran Any updates? |
Replace 'slides' with the name of the array that contains the slide items. For example, instead of slides.length use yourArray.length On Nov 14, 2016 18:08, Pam notifications@github.com wrote: @akiranhttps://github.com/akiran {slides.length > 0 ? {slides} : null } didn't work for me. Any updates? You are receiving this because you were mentioned. |
Thanks for the quick response @samplefrequency Unfortunately it still doesn't work. Like you, my array starts off empty and is later populated via AJAX called after the Redux store has been updated (since it needs the new data from the redux store to make the call). As you suggested, I have replaced it with my own array, and I've also confirmed the length of said array - The below is my renderGallery handler which I call when rendering renderGallery() {
if (this.props.listingGalleryImages.data !== undefined) {
const galleryAssets = this.props.listingGalleryImages.data;
const images = galleryAssets.map((asset, index) => {
return (
<div data-index={index} key={index}><img key={asset.id} src={asset.url} /></div>
);
});
return images;
}
} And inside the render: <div className="container" >
{this.renderGallery(listing) !== undefined && this.renderGallery(listing).length > 0 ?
<Slider{...settings}>
<div>{this.renderGallery(listing)}</div>
</Slider> : null }
{this.renderGallery(listing) !== undefined ? this.renderGallery(listing).length : null}
</div> I don't know if this is clear enough, happy to clarify further. Btw, I'm using "react-slick": "^0.14.5", |
Solved it. Had help from a colleague and he pointed out that I needed only to take out the <Slider{...settings}>
<div>{this.renderGallery(listing)}</div>
</Slider> : null } Apparently, if I leave it there, the Slider will pick up that one big and count that, which means it will not render according to the other many s within it.
Side note: I didn't even need the data-index in the .map, though the ternary is still needed for fallback purposes. Code now looks like this: {this.props.listingGalleryImages.loaded === true &&
<div className="container">
{this.renderGallery(listing).length > 0 ?
<Slider {...settings}>{this.renderGallery(listing) </Slider> : null }
</div>
} |
@ypyang237 Just as a side note, instead of the ternary
You could actually use && to make it shorter:
|
@szimek Thanks, this works for me! 👍 |
@anonmily thanks i have the same problem as you , it works! |
If {...settings} you set |
Doesn't work with react components |
I also stuck in this issue, but now it's working fine for me:
I hope it helps. |
This issue is fixed in master |
When will this fix be added to NPM? |
Still facing the same issue with this release -- |
Make sure Your slide component could look something like this:
This fixed it for me. |
How is it possible to do what @ypyang237 did first? I need a slider that has that setup
And slick only to pick up like |
Hello I still have the same problem... what the hell is going on... look at the width size... my code : <div>
<h2>Custom Arrows</h2>
<Slider {...settings}>
<div>
<h3>1</h3>
</div>
<div>
<h3>2</h3>
</div>
<div>
<h3>3</h3>
</div>
<div>
<h3>4</h3>
</div>
<div>
<h3>5</h3>
</div>
<div>
<h3>6</h3>
</div>
</Slider>
</div> |
I still have a problem at rendering dynamic children. My config:
I've tried all tricks and tips and "solutions" above but nothing seem to work.
|
@kevin700brands You might have missed importing the CSS files: just try adding the two lines of code in ur app.js file:
|
I am using version 0.29.0 and still have issues regarding broken slider. Initially everything is fine, when i load the page, but when i move to another page and return, all my data are there, I put log to track changes, but my slider is not visible... Can anyone relate to this behavior? I put all the changes mentioned here bit it does not work... My Settings object is: const settings: Settings = { nextArrow: , }; My component code is: return (
|
When I removed first container div, slider now works, its not broken, but my .css is now... Why is this happening? |
If I render Slider as below:
nextProps.children.length
incomponentWillReceiveProps
of classInnerSlider
will always returns 1 which breaks the sliding logic.Does Slider not expect dynamic children?
The text was updated successfully, but these errors were encountered: