Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to solve ESLint is missing in props validation in React?

I am using React to do create a small Carousel using swiperJS and I have the following code:

import { Swiper } from "swiper/react";
import React from "react";

export default function SwiperContainer(props) {
    const { slides, navigation = true, clickable = true, dynamicBullets = true } = props;
    return (<Swiper dir="rtl" lazy={true} slidesPerView={1} spaceBetween={30} breakpoints={{
        // when window width is >= 320px
        320: {
            slidesPerView: 2, spaceBetween: 10
        }, // when window width is >= 640px
        640: {
            slidesPerView: 2, spaceBetween: 10
        }, // when window width is >= 768px
        768: {
            slidesPerView: 2, spaceBetween: 10
        }, // when window width is >= 1024px
        1024: {
            slidesPerView: 4, spaceBetween: 10
        },
    }} navigation={navigation} pagination={{
        "clickable": { clickable }, "dynamicBullets": { dynamicBullets }
    }} className="what-customer-say-swiper pt-1 pb-1" style={{ zIndex: 0, }}>
        {slides}
    </Swiper>);
}

And I am using ESLint with my project but it gives me this error.

Line 5:13:  'slides' is missing in props validation          react/prop-types
Line 5:21:  'navigation' is missing in props validation      react/prop-types
Line 5:40:  'clickable' is missing in props validation       react/prop-types
Line 5:58:  'dynamicBullets' is missing in props validation  react/prop-types

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You should define PropTypes for your component

export default function SwiperContainer(props) {
    const { slides, navigation = true, clickable = true, dynamicBullets = true } = props;
    return (<Swiper dir="rtl" lazy={true} slidesPerView={1} spaceBetween={30} breakpoints={{
        // when window width is >= 320px
        320: {
            slidesPerView: 2, spaceBetween: 10
        }, // when window width is >= 640px
        640: {
            slidesPerView: 2, spaceBetween: 10
        }, // when window width is >= 768px
        768: {
            slidesPerView: 2, spaceBetween: 10
        }, // when window width is >= 1024px
        1024: {
            slidesPerView: 4, spaceBetween: 10
        },
    }} navigation={navigation} pagination={{
        "clickable": { clickable }, "dynamicBullets": { dynamicBullets }
    }} className="what-customer-say-swiper pt-1 pb-1" style={{ zIndex: 0, }}>
        {slides}
    </Swiper>);
}

SwiperContainer.propTypes = {
  slides: PropTypes.arrayOf(PropTypes.element),
  navigation: PropTypes.bool,
  clickable: PropTypes.bool,
  dynamicBullets: PropTypes.bool 
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading