femioladeji / react-slideshow

A react component for slideshow supporting slide, fade and zoom
https://react-slideshow-image.netlify.app/
MIT License
359 stars 71 forks source link

Slide often missing on large screen #222

Closed DhaniAM closed 8 months ago

DhaniAM commented 8 months ago

So here's what happen:

*Update: If I set infinite to false, then I can see the Slide content but it's not full width. The left & right arrows are in the right place, but the contents are not. After I resize screen, then it'll become full width. If I set infinite to true, then I can't see the Slide content at all like I said before.

Here's my code

const KategoriPilihanItem = (props: KategoriPilihanItemType) => {
    <ul className='hidden lg:block'>
        <Slide
            autoplay={false}
            easing={'ease'}
            infinite={true}
            slidesToShow={8}
            slidesToScroll={3}
        >
            <KategoriPilihanItem key={"semua"} id={"semua"} kategori='Lihat Semua'/>
            {Boolean(kategoriList) && kategoriList.map((item: any, idx: number) => {
                return (
                <KategoriPilihanItem
                    kategori={item.nama}
                    key={idx}
                    id={item.id}
                />
                )
            })}
        </Slide>
    </ul>
}

const KategoriPilihanItem = (props: KategoriPilihanItemType) => {
    const router: NextRouter = useRouter()

    const onClick = (_: any): void => {
        void router.push(`/produk/kategori/${props.id}`)
    }
    const kategori = props.kategori
    const kategoriIcon = kategori?.toLowerCase()
    .replace(/ & /g, '  -')
    .replace(/ /g, '-')
    .replace(/\//g, '-')

    return (
        <li
        onClick={onClick}
        className='flex cursor-pointer flex-grow flex-col flex-nowrap items-center
            transition-all hover:-mt-2 hover:mb-2 py-2 mr-3 lg:mr-0 h-full hover:bg-borneo-green-lighten2'>
        <div>
                <Image
                    id={props.id}
                    src={`/kategori/${kategoriIcon}.svg`}
                    alt={kategori}
                    className='object-contain w-11 h-11 lg:w-12 lg:h-12 xl:w-16 xl:h-16'
                    width={10}
                    height={10}
                />
        </div>
        <div
                id={props.id}
                className='text-11px text-borneo-purple w-20 text-center lg:w-24'>
                {kategori}
        </div>
        </li>
    )
}
femioladeji commented 8 months ago

thanks for raising this issue. We'll look into it and get back to you

DhaniAM commented 8 months ago

I just change my initial useState from [ ] into null and somehow this issue is gone. I don't understand why but it works.

from:

const [kategoriList, setKategoriList] = useState<Array<any>>([])

// inside KategoriPilihan component contain the Slide component
{kategoriList ? <KategoriPilihan data={kategoriList}/> : <Loading/>}

change into:

const [kategoriList, setKategoriList] = useState<any>(null)

// inside KategoriPilihan component contain the Slide component
{kategoriList ? <KategoriPilihan data={kategoriList}/> : <Loading/>}