A
A
Alexander2021-06-08 20:02:16
React
Alexander, 2021-06-08 20:02:16

How to style Swiper in styled components?

Can you please tell me how to style Swiper in styled components?
This styling method works, but the slider functionality stops working completely, although in react-router-dom these problems did not arise when styling Link

<Slider 
        spaceBetween={50}
        slidesPerView={3}
        onSlideChange={() => console.log('slide change')}
        onSwiper={(swiper) => console.log(swiper)}
        pagination={{ clickable: true }}
      >
        <SliderItem >Slide 1</SliderItem >
        <SliderItem >Slide 2</SliderItem >
        <SliderItem >Slide 3</SliderItem >
        <SliderItem >Slide 4</SliderItem >
        ...
      </Slider >


import { Swiper, SwiperSlide } from 'swiper/react'

export const Slider = styled(Swiper)`
  /* background-color: red; */
`
export const SliderItem = styled(SwiperSlide)``

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vladcorn, 2021-11-08
@vladcorn

SliderItem = styled.div``

<Slider>
{data.map((item)=>{
return (
<SwiperSlide key={item.id}>
   <SliderItem {...item}>
</SwiperSlide>)
})}
</Slider>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question