react-slick: Cannot read property 'getBoundingClientRect' of null
Not sure how it the fix here 328, I did this:
render() {
let imgTpl = (images || []).map((image, index) => {
return (
<div key={image.Id} >
<img src={image.url} /></div>
);
});
}
return(
<Slider {...settings}>
{ imgTpl }
</Slider>
)
There is a div around the image items but it still does not work.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 35 (6 by maintainers)
Commits related to this issue
- Still fixing rendering issue in User page, reference: https://github.com/akiran/react-slick/issues/555 — committed to david-zou/flashcards by david-zou 7 years ago
This happens anytime your slides are custom React components. For example, this doesn’t work…
This works…
this.list
ref doesn’t get setMake sure imgDivs is not empty inside Slider
@thangytp I actually tried this already and it does not work for me, I have this instead but think it is the same thing:
and then call the slider:
Sure - this doesn’t work:
and SliderItem is:
const SliderItem = (props) => <div><h3>{props.slide.tagline}</h3></div>
However, this works:
But it kind of counteracts the point of breaking the code out to a functional component, don’t you think?
UPDATE: I just noticed that the author replied in #328 that wrapping in a div is his suggestion or as an alternative passing in props to the root component should do the job. In my case, doing the following instead of wrapping in a div worked for me, and seems tidier to me:
const SliderItem = (props) => <div {...props}><h3>{props.slide.tagline}</h3></div>
So I’m happy, but that really needs to go into the Readme!
Currently, this library relies on the user’s components (slides) forwarding the libraries
ref
prop to their DOM elements. This means…ref
prop to their outermost DOM elementref
A better solution would probably be to wrap all user components in a style-less
div
that fills its container and put the libraryref
there and use this for all library calculations. Something like this (psuedo-code)…Warning: I haven’t actually read the code and I’m not actually using this library or I’d send a PR. Just trying to help as I’m quite familiar with
ref
issues in ReactI’m using jest to test my components and I can’t make this work, wrapping the components with a div doesn’t help
We noticed the same error when rendering a slider that has an empty array of childcomponents:
Our solution was to check for empty array and not render the slider at all.
Just wanted to jump in here and say that I’m getting this error also while running Jest tests on a Carousel component that uses react-slick under the hood.
hi @sayayinR, have you try to wrap {imgDivs} with
<div>
like this:<div>{imgDivs}</div>
if it works and renders duplicate content, you should try the code in pure javascript like me.
Hi there, I’ve resolved it. Here is my solution.
Hope this help to all you!
If you are mapping from props, e.g
Check if the props are a null before you check the length of the props.
This worked for me.
@shafy Absolutely, I just meant that I was happy to be able to get on with my own project… At the time, I removed the warning as follows:
For me the problem was that my
<Slider>
component didn’t have any children (in a particular use case).@seleckis React does allow
div
(and everything else) to have akey
.key
is a special prop that does not get added to the actual DOM, so it’s allowed (and actually required). Otherwise you could never render a list of anything except custom components that explicity filter out thekey
prop. That would be awful.Here is an example. Notice there are no warnings in the console