Creating a Card Slider with React JS using React Slick

Posted by

In this tutorial, we will learn how to create a card slider in React JS using the React Slick library. The card slider is a popular UI component that allows users to navigate through a series of cards or images in a slider format.

To get started, make sure you have React JS installed in your development environment. If not, you can install it by running the following command:

npx create-react-app card-slider-react-slick

Once you have created a new React project, navigate into the project directory by running:

cd card-slider-react-slick

Next, we need to install the React Slick library. To do this, run the following command in your terminal:

npm install react-slick slick-carousel

Now that we have installed the necessary libraries, let’s create a new component called CardSlider in the src directory. Here is an example of how the component should look:

import React from 'react';
import Slider from 'react-slick';
import 'slick-carousel/slick/slick.css';
import 'slick-carousel/slick/slick-theme.css';

const CardSlider = () => {
  const settings = {
    dots: true,
    infinite: true,
    speed: 500,
    slidesToShow: 1,
    slidesToScroll: 1
  };

  return (
    <Slider {...settings}>
      <div>
        <h3>Card 1</h3>
      </div>
      <div>
        <h3>Card 2</h3>
      </div>
      <div>
        <h3>Card 3</h3>
      </div>
    </Slider>
  );
};

export default CardSlider;

In the code above, we import the Slider component from react-slick and define some settings for the slider. We then render a series of card components inside the slider.

Now, we need to import and use the CardSlider component in our App.js file. Here’s how you can do that:

import React from 'react';
import CardSlider from './CardSlider';

function App() {
  return (
    <div className="App">
      <h1>Card Slider</h1>
      <CardSlider />
    </div>
  );
}

export default App;

Now, when you run npm start in your terminal and view your React app in the browser, you should see a simple card slider with three cards.

You can customize the settings object in the CardSlider component to adjust the behavior and appearance of the slider. For example, you can change the number of slides to show at a time, the speed of the slider, and whether or not to display navigation dots.

That’s it! You have successfully created a card slider in React JS using the React Slick library. Experiment with different settings and styles to create a card slider that best fits your project’s needs.

0 0 votes
Article Rating
46 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@saikiran0311
3 months ago

please could you explain in details about in the public folder in the students details

@nehalsalunke30
3 months ago

Hello please please reply me as soon as possible
I followed each and every step in this video and at the end the arrows was not there. Only I am able to scroll through dots.
Please tell me if there possibly mistake I made during this process..
And also I have not used tailwind classes to some elements. Instead I used external css. But its all working fine.. just want to know that how to display that arrows..

@MohammedHusainmobikira
3 months ago

WOW! really you made it very easy… Thank you so much.

@KhoaHo-jh9yz
3 months ago

thank you

@fatimaiqra2169
3 months ago

thanks a lot, u=your video is really time saving

@SiddhiRanpise-g5k
3 months ago

Thankyou,This helped a lot! Subscribing rightaway!!

@KiranBadgujar-di2ki
3 months ago

For mobile how it was going to look please one video on that please Mam

@apurwarokade3863
3 months ago

How can we change colour of the arrow bar

@felipeandreas3224
3 months ago

Error: Super expression must either be null or a function What is the reason for this error?

@Bigi352
3 months ago

Thank you for sharing😭😭😭, God Bless you greatly & increase you,I have been battling with this for like 2 days now until I decided to search YT and found your video where u used react.

@DanielOscarKantong
3 months ago

how do i change the button color mrs.etisha??

@asmusjk
3 months ago

If u are using tailwind, use this to make it responsive:

const Services = () => {

var settings = {

accessibility:true,

dots: true,

infinite: true,

speed: 500,

slidesToShow: 3,

slidesToScroll: 1,

responsive: [

{

breakpoint: 1920,

settings: {

slidesToShow: 4,

slidesToScroll: 1,

infinite: true,

dots: true

}

},

{

breakpoint: 1536,

settings: {

slidesToShow: 4,

slidesToScroll: 1,

infinite: true,

dots: true

}

},

{

breakpoint: 1280,

settings: {

slidesToShow: 3,

slidesToScroll: 1,

infinite: true,

dots: true

}

},

{

breakpoint: 1024,

settings: {

slidesToShow: 2,

slidesToScroll: 1,

infinite: true,

dots: true

}

},

{

breakpoint: 800,

settings: {

slidesToShow: 2,

slidesToScroll: 1,

initialSlide: 1

}

},

{

breakpoint: 640,

settings: {

slidesToShow: 2,

slidesToScroll: 1,

initialSlide: 1

}

},

{

breakpoint: 480,

settings: {

slidesToShow: 1,

slidesToScroll: 1

}

}

]

};

return (

};

<div className='m-10 sm:mx-10 md:mx-40 lg:mx-30 xl:mx-40 2xl:mx-60'>
<Slider {…settings}>

@carlosloqueando904
3 months ago

gracias <3

@sudarshanpatekar5632
3 months ago

Well the slider looks really good, but for me the cards just take up the whole screen width, but even I want it in the center and also I am not able to see the left arrow, its almost like its not there

@razarajpoot9811
3 months ago

thank you very much

@215ariley
3 months ago

so helpful, thank you! Also, i love the way you pronounce carousel

@capnajish9745
3 months ago

how to add those images?

@Umeed_
3 months ago

no link to the source no direct link to the git .. just waste of time

@fluntimes
3 months ago

This was really helpful. I struggled with a few other libraries/tutorials but this one hit the mark and swiftly too! Great work 🙂

@lianosh_hamalka
3 months ago

thank you for this video queen!