Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for How to use React-owl-carousel in 2025
Ifeanyi Chima
Ifeanyi Chima

Posted on • Edited on

     

How to use React-owl-carousel in 2025

While I was working on creating a website. I wanted to implement a sliding carousel feature.

Image description

I loveOwl Carousel, so I settled on using it.

Installation

You need to install packages such as@rollup andreact-owl-carousel

npm i react-owl-carousel @rollup/plugin-inject
Enter fullscreen modeExit fullscreen mode

jQuery

You need to inject jQuery into the project. If you are usingvite, which is a javascript bundler, here is how you do it.

This should be done in yourconfig.js

import{defineConfig}from'vite'importinjectfrom'@rollup/plugin-inject';importreactfrom'@vitejs/plugin-react-swc'// https://vitejs.dev/config/exportdefaultdefineConfig({plugins:[react(),inject({$:'jquery',jQuery:'jquery','window.jQuery':'jquery',}),],})
Enter fullscreen modeExit fullscreen mode

App.jsx

You need to make jQuery available to the entire App/Project

import'./App.css'import*as$from"jquery"// ---> this lineimportHeaderfrom"./components/Header"importHerofrom"./components/Hero"functionApp(){return(<><Header/><Hero/><Simple/><Footer/></>)}exportdefaultApp
Enter fullscreen modeExit fullscreen mode

Image description

Owl Carousel CSS

You need to link theowl-carousel css code in yourmain.jsx

importReactfrom'react'importReactDOMfrom'react-dom/client'importAppfrom'./App.jsx'import'./index.css'import'owl.carousel/dist/assets/owl.carousel.css';{/* this line */}import'owl.carousel/dist/assets/owl.theme.default.css';{/* this line */}
Enter fullscreen modeExit fullscreen mode

Component

You can use theOwl carousel component in your React component. You pass in options to modify how the component behaves.

importOwlCarouselfrom'react-owl-carousel';constFeatures=()=>{constoptions={responsive:{0:{items:1,},400:{items:1,},600:{items:1,},700:{items:1,},800:{items:2,},1000:{items:3,}},nav:false,dots:true}return(<OwlCarouselclassName='owl-theme section'loopmargin={20}autoplay{...options}>{/* 1 */}<divclassName="review item"><h3>24hourup-time</h3><p>TheAPIwillalwaysbeavailablewithzerolatencyandlittletonodown-time</p><divclassName="review-img"><imgsrc="/trust.svg"alt=""/></div></div>{/* 2 */}<divclassName="review item"><h3>Globalcoverage</h3><p>Viewthelatestliveexchangeratesforallthecrypto-currenciesavailableworldwide.</p><divclassName="review-img"><imgsrc="/globe.svg"alt=""/></div></div>{/* 3 */}<divclassName="review item"><h3>GreatDocumentation</h3><p>Toassistdevelopers,wehavecuratedaworld-classNamedocumentationfortheAPI</p><divclassName="review-img"><imgsrc="/shield.svg"alt=""className="trust"/></div></div></OwlCarousel>)}exportdefaultFeatures
Enter fullscreen modeExit fullscreen mode

Buy Me A Coffee

Thank you, Please follow me

HTML GitHub

Top comments(2)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
iamdipankarpaul profile image
Dipankar Paul
Hi, I am Dipankar Paul, an electrical engineering graduate and a self-taught web developer skilled in HTML, CSS, JavaScript, React., Tailwind CSS, Redux, Redux Toolkit Query, Zustand, MUI, etc..
  • Location
    Siliguri, West Bengal, India
  • Pronouns
    He/him
  • Work
    Arkedia Marketing, Siliguri, West Bengal, India
  • Joined

I also use owl this but autoplay is not working. Do you know why?

Warning: Using UNSAFE_componentWillReceiveProps in strict mode is not recommended and may indicate bugs in your code. See https://reactjs.org/link/unsafe-component-lifecycles for details.* Move data fetching code or side effects to componentDidUpdate.* If you're updating state whenever props change, refactor your code to use memoization techniques or move it to static getDerivedStateFromProps. Learn more at: https://reactjs.org/link/derived-statePlease update the following components: ReactOwlCarousel2
Enter fullscreen modeExit fullscreen mode

I am getting this error

CollapseExpand
 
ifeanyichima profile image
Ifeanyi Chima
I write articles to teach the world what I know.
  • Email
  • Location
    Lafayette, Louisiana, USA
  • Education
    Bachelor of Science, Computer science
  • Pronouns
    he/him
  • Work
    Software Developer / Designer
  • Joined

The issue comes from the library or package (React-owl-carousel). We need to wait for their developers to make the necessary updates or correction.

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

I write articles to teach the world what I know.
  • Location
    Lafayette, Louisiana, USA
  • Education
    Bachelor of Science, Computer science
  • Pronouns
    he/him
  • Work
    Software Developer / Designer
  • Joined

More fromIfeanyi Chima

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp