Search code examples
reactjsowl-carousel

react owl carousel is hiding after when I refreshing page


I am using the react-owl-carousel package and when I refresh the page, the carousel disappears. What should I do?

<OwlCarousel
                items={3}
                className="owl-theme"
                loop
                nav
                margin={8} 
            >
                {
                    news.map((newsItem) => (
                        <NewsContent key={newsItem.id} title={newsItem.title} text={newsItem.text.substring(0, 150)} id={newsItem.id} datetime={newsItem.createdDate.split('T')[0]} />
                    ))

                }
            </OwlCarousel>

Solution

  • Try this code:

    {
    news &&(
    <OwlCarousel
                    items={3}
                    className="owl-theme"
                    loop
                    nav
                    margin={8} 
                >
                    {
                        news.map((newsItem) => (
                            <NewsContent key={newsItem.id} title={newsItem.title} text={newsItem.text.substring(0, 150)} id={newsItem.id} datetime={newsItem.createdDate.split('T')[0]} />
                        ))
    
                    }
                </OwlCarousel>
    )
    }