React Swipeable Views Utilities

0.14.1 · maintenance · verified Tue Apr 21

react-swipeable-views-utils provides Higher-Order Components (HOCs) and utilities designed to extend the functionality of `react-swipeable-views`. This package offers features like automatic slide progression (`autoPlay`), virtualized rendering for performance with many slides (`virtualize`), and keyboard navigation (`bindKeyboard`). The current stable version is `0.14.1`. Historically, releases have been somewhat irregular, with the last significant update over a year ago, suggesting a maintenance rather than active development phase. Its primary differentiator is its tight integration with `react-swipeable-views`, providing common advanced behaviors out-of-the-box without requiring complex custom implementations. It relies on React's HOC pattern to inject enhanced behavior into a base `SwipeableViews` component.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use the `autoPlay` HOC with `react-swipeable-views` to create a self-advancing carousel, including basic navigation dots.

import * as React from 'react';
import SwipeableViews from 'react-swipeable-views';
import { autoPlay } from 'react-swipeable-views-utils';

const AutoPlaySwipeableViews = autoPlay(SwipeableViews);

const DemoCarousel = () => {
  const [index, setIndex] = React.useState(0);

  const handleChangeIndex = (idx) => {
    setIndex(idx);
  };

  return (
    <div style={{ maxWidth: 400, margin: 'auto' }}>
      <h2>Auto-Playing Carousel</h2>
      <AutoPlaySwipeableViews
        index={index}
        onChangeIndex={handleChangeIndex}
        enableMouseEvents
        interval={3000}
      >
        <div style={{ background: '#f44336', height: 200, display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
          <h3>Slide 1</h3>
        </div>
        <div style={{ background: '#2196f3', height: 200, display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
          <h3>Slide 2</h3>
        </div>
        <div style={{ background: '#4caf50', height: 200, display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
          <h3>Slide 3</h3>
        </div>
      </AutoPlaySwipeableViews>
      <div style={{ textAlign: 'center', marginTop: 10 }}>
        {['●', '●', '●'].map((dot, i) => (
          <span
            key={i}
            style={{
              cursor: 'pointer',
              margin: '0 5px',
              color: i === index ? '#333' : '#bbb',
              fontSize: '24px'
            }}
            onClick={() => setIndex(i)}
          >
            {dot}
          </span>
        ))}
      </div>
    </div>
  );
};

export default DemoCarousel;

view raw JSON →