79781228

Date: 2025-10-02 19:10:05
Score: 0.5
Natty:
Report link

Recently i used the splideJS for one of my NextJs projects and faced the same issue (ChatGPT was also not that helpful)

They have a separate react-splide package but it did not work for me
These are my exact steps

Install both splide and auto scroll extension

npm install @splidejs/splide @splidejs/splide-extension-auto-scroll

Import the splice to the component
(Without the css the slides would not appear)

import { Splide } from '@splidejs/splide';
import { AutoScroll } from '@splidejs/splide-extension-auto-scroll';
import '@splidejs/splide/css';

Mount the splide code in useEffect

  useEffect(() => {

    const splide = new Splide('.splide', {
      type: 'loop',
      drag: 'free',
      focus: 'center',
      perPage: 3,
      arrows: true,
      pagination:true,
      autoScroll: {
        speed: 1,
        pauseOnHover: true,
        pauseOnFocus: true,
        rewind: true,
      },
    });

    splide.mount({ AutoScroll });

    return () => {
      splide.destroy();
    };
  }, []);

Finally add the splide items to the component

    <div className="splide">
      <div className="splide__track">
        <ul className="splide__list">

          <li className="splide__slide">
            <img src="1.jpg" alt="Image 1" />
          </li>
          <li className="splide__slide">
            <img src="2.jpg" alt="Image 1" />
          </li>
          <li className="splide__slide">
            <img src="4.jpg" alt="Image 1" />
          </li>
          <li className="splide__slide">
            <img src="1.jpg" alt="Image 1" />
          </li>
        </ul>
      </div>
    </div>

As i noticed class names and element structure should be as it is.
Feel free to correct me if I am wrong

Thanks

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Blacklisted phrase (1): did not work
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: jayangaVliyanage