React-slick: React component in react slick

Created on 9 Feb 2018  路  2Comments  路  Source: akiran/react-slick

When i pass react component in react slick slider but it does not show my component in slider. Is there any way to pass my react component . As i pass my grid component in slider. But nothing show.

Most helpful comment

Without seeing your code, I am not sure what exactly the issue is, but I might have a hunch.
Let's say this is your parent component, call it Carousel.

export default class Carousel extends Component {
  render() {
    return (
      <div className="Carousel">
        <Slider>
          <CarouselItem/>
          <CarouselItem/>
          <CarouselItem/>
        </Slider>
      </div>
    )
  }
}

Then in your CarouselItem component, you need to make sure to pass in a destructured this.props to your element like so:

export default class CarouselItem extends Component {
  render() {
    return (
     <div {...this.props}>
       <h1>Hello!</h1>
     </div>
    )
  }
}

This funny ...this.props operator basically gets all the key-values from this.props and we now pass it to the div. This is important because there are many react-slick specific props passed in and our custom slides also require them. Hope this helps.

All 2 comments

Without seeing your code, I am not sure what exactly the issue is, but I might have a hunch.
Let's say this is your parent component, call it Carousel.

export default class Carousel extends Component {
  render() {
    return (
      <div className="Carousel">
        <Slider>
          <CarouselItem/>
          <CarouselItem/>
          <CarouselItem/>
        </Slider>
      </div>
    )
  }
}

Then in your CarouselItem component, you need to make sure to pass in a destructured this.props to your element like so:

export default class CarouselItem extends Component {
  render() {
    return (
     <div {...this.props}>
       <h1>Hello!</h1>
     </div>
    )
  }
}

This funny ...this.props operator basically gets all the key-values from this.props and we now pass it to the div. This is important because there are many react-slick specific props passed in and our custom slides also require them. Hope this helps.

You can check this example https://github.com/akiran/react-slick/blob/master/examples/CustomSlides.js

you can filter this.props before passing to div if necessary

Was this page helpful?
0 / 5 - 0 ratings

Related issues

briziel picture briziel  路  3Comments

adamthewan picture adamthewan  路  4Comments

Exomnius picture Exomnius  路  3Comments

eternalsky picture eternalsky  路  3Comments

slashwhatever picture slashwhatever  路  3Comments