Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

embla-carousel-react

Package Overview
Dependencies
Maintainers
1
Versions
121
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

embla-carousel-react

A lightweight carousel library with fluid motion and great swipe precision

  • 7.0.0-rc01
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
795K
increased by0.67%
Maintainers
1
Weekly downloads
 
Created

What is embla-carousel-react?

The embla-carousel-react package is a lightweight and customizable carousel library for React. It provides a performant and flexible way to create carousels and sliders in React applications.

What are embla-carousel-react's main functionalities?

Basic Carousel

This code demonstrates how to create a basic carousel using embla-carousel-react. It initializes the carousel with default options and includes three slides.

import React from 'react';
import { EmblaCarouselReact } from 'embla-carousel-react';

const BasicCarousel = () => {
  const options = {};
  return (
    <EmblaCarouselReact options={options}>
      <div className="embla__slide">Slide 1</div>
      <div className="embla__slide">Slide 2</div>
      <div className="embla__slide">Slide 3</div>
    </EmblaCarouselReact>
  );
};

export default BasicCarousel;

Autoplay

This code demonstrates how to implement an autoplay feature in the carousel. The carousel will automatically scroll to the next slide every 3 seconds.

import React, { useEffect } from 'react';
import { EmblaCarouselReact } from 'embla-carousel-react';

const AutoplayCarousel = () => {
  const options = { loop: true };
  let embla;

  useEffect(() => {
    if (embla) {
      const autoplay = setInterval(() => {
        embla.scrollNext();
      }, 3000);
      return () => clearInterval(autoplay);
    }
  }, [embla]);

  return (
    <EmblaCarouselReact options={options} emblaRef={(e) => (embla = e)}>
      <div className="embla__slide">Slide 1</div>
      <div className="embla__slide">Slide 2</div>
      <div className="embla__slide">Slide 3</div>
    </EmblaCarouselReact>
  );
};

export default AutoplayCarousel;

Custom Navigation

This code demonstrates how to add custom navigation buttons to the carousel. The buttons allow users to manually scroll to the previous or next slide.

import React, { useRef } from 'react';
import { EmblaCarouselReact } from 'embla-carousel-react';

const CustomNavigationCarousel = () => {
  const emblaRef = useRef(null);

  const scrollPrev = () => emblaRef.current.scrollPrev();
  const scrollNext = () => emblaRef.current.scrollNext();

  return (
    <div>
      <EmblaCarouselReact emblaRef={emblaRef}>
        <div className="embla__slide">Slide 1</div>
        <div className="embla__slide">Slide 2</div>
        <div className="embla__slide">Slide 3</div>
      </EmblaCarouselReact>
      <button onClick={scrollPrev}>Previous</button>
      <button onClick={scrollNext}>Next</button>
    </div>
  );
};

export default CustomNavigationCarousel;

Other packages similar to embla-carousel-react

Keywords

FAQs

Package last updated on 30 Jun 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc