Looking for a solution to adjust the number of elements displayed in my React Carousel based on available size? I have a React Carousel that currently shows 3 elements at one time. Here is the code snippet:
const RCarousel = ({items}) => {
const numItems = 3;
return (
<Carousel
numItemsPerView={numItems}
>
{
items.map(
(item) => <Item item={item} />
)
}
</Carousel>
)
}
I am interested in changing the value of numItems
to 2 when the RCarousel is at "tablet size", and to 1 when it is at "mobile size". However, given that RCarousel's width may vary depending on the window size, any advice on how to achieve this dynamically? :)