Registry / web-framework / react-touch-carousel

react-touch-carousel

JSON →
library0.10.2jsnpmunverified

react-touch-carousel is a micro carousel framework for React.JS that prioritizes highly customizable user experiences over predefined configurations. Instead of offering numerous options for static DOM nodes, it employs an inversion of control pattern, allowing developers to fully dictate content rendering and styling dynamically. Its current stable version is 0.10.2, and releases appear tied to updates in its underlying animation library, `react-spring`, rather than a fixed cadence. This differentiates it significantly from more opinionated carousel libraries like Swiper or Slick, providing unparalleled flexibility for bespoke designs and advanced UI requirements where designers demand specific, non-standard behaviors.

npm install react-touch-carousel
INSTALL
IMPORT
SIG · REACT-TOUCH-CAROUS
R
react-touch-carousel
web-frameworkjavascriptv0.10.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

TouchCarousel
import TouchCarousel from 'react-touch-carousel';
import { TouchCarousel } from 'react-touch-carousel';
TouchCarousel is a default export, not a named one. Using named import will result in an undefined component.

This quickstart demonstrates a basic looping carousel with autoplay functionality. It shows how to provide a custom container component and a card renderer, leveraging `listOfData` to dynamically display content with custom styling and animations via inline styles and `transform` properties.

import TouchCarousel from 'react-touch-carousel'; import React, { useRef } from 'react'; const listOfData = [ { id: 1, title: 'Slide A', color: '#ffadad' }, { id: 2, title: 'Slide B', color: '#ffd6a5' }, { id: 3, title: 'Slide C', color: '#fdffb6' }, { id: 4, title: 'Slide D', color: '#caffbf' }, { id: 5, title: 'Slide E', color: '#9bf6ff' } ]; function CarouselContainer({ cursor, carouselState, onTouchStart, onTouchMove, onTouchEnd, onTouchCancel, children }) { const containerRef = useRef(); return ( <div ref={containerRef} style={{ width: '100%', maxWidth: '500px', height: '250px', overflow: 'hidden', position: 'relative', display: 'flex', alignItems: 'center', justifyContent: 'center', border: '1px solid #eee', margin: '20px auto' }} onTouchStart={onTouchStart} onTouchMove={onTouchMove} onTouchEnd={onTouchEnd} onTouchCancel={onTouchCancel} > {children} </div> ); } function renderCard(index, modIndex, cursor) { const item = listOfData[modIndex]; const translateX = (index - cursor) * 375; // Assuming cardSize 375px return ( <div key={item.id} style={{ position: 'absolute', transform: `translateX(${translateX}px)`, width: '350px', height: '180px', backgroundColor: item.color, borderRadius: '12px', display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: '1.8em', color: 'white', boxShadow: '0 6px 12px rgba(0,0,0,0.2)', transition: 'transform 0.3s ease-out' }} > {item.title} </div> ); } // To render this in a React application: // export default function App() { // return ( // <TouchCarousel // component={CarouselContainer} // cardCount={listOfData.length} // cardSize={375} // renderCard={renderCard} // loop // autoplay={3000} // defaultCursor={0} // onRest={(idx, modIdx) => console.log(`Carousel rested at index: ${idx}, modIndex: ${modIdx}`)} // /> // ); // }
Debug
Known issues
breakingThe underlying animation library changed from `react-motion` to `react-spring`. This impacts spring-related props.
fix
Replace `props.stiffness` with `props.tension` and `props.damping` with `props.friction` when configuring spring animations.
affects: >=0.9.0
gotchaThe bundle size significantly increased with the v0.9.0 release due to the switch to `react-spring`.
fix
Be aware of the increased bundle size. If bundle size is critical, consider analyzing the impact or exploring alternatives if the new features are not strictly necessary.
affects: >=0.9.0
gotchaFrequent major version upgrades of `react-spring` (v7->v8 in 0.9.4, v8->v9 in 0.10.2) indicate active development but may introduce subtle behavioral changes or require users to keep their `react-spring` dependency aligned if interacting directly with it.
fix
Always check release notes for `react-touch-carousel` and `react-spring` when upgrading to ensure compatibility and understand potential behavioral shifts.
affects: >=0.9.4
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'stiffness')
Attempting to use `stiffness` prop, which was removed after the transition from `react-motion` to `react-spring`.
fix
Update your code to use `tension` instead of `stiffness` and `friction` instead of `damping` for spring configurations.
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components)... Check the render method of `App`.
Incorrect import of `TouchCarousel`. It's a default export, not a named one.
fix
Change `import { TouchCarousel } from 'react-touch-carousel';` to `import TouchCarousel from 'react-touch-carousel';`
Upgrade
Version history
0.10.2latest on npm
Audit
Dependencies
reactrequiredPeer dependency for React applications.
react-domrequiredPeer dependency for rendering React components.
react-springrequiredInternal animation library. Major version upgrades have led to breaking changes in `react-touch-carousel`'s API.
Agent activity
4 hits · last 30 days
node
4
Resources
react-touch-carousel — npm install react-touch-carousel · libregistry