react-image-gallery vs react-alice-carousel vs react-responsive-carousel vs react-slick
React 用カルーセルライブラリの技術比較
react-image-galleryreact-alice-carouselreact-responsive-carouselreact-slick類似パッケージ:

React 用カルーセルライブラリの技術比較

react-alice-carouselreact-image-galleryreact-responsive-carouselreact-slick は、React アプリケーションでスライドショーやカルーセルを実装するための主要なライブラリです。それぞれ目的が異なり、react-slick は伝統的な多機能カルーセル、react-responsive-carousel は軽量で SSR に強く、react-image-gallery は画像専用のライトボックス機能に特化、react-alice-carousel はタッチ操作とレスポンシブ設計に優れています。開発者はプロジェクトの要件に応じて、依存関係、SSR 対応、カスタマイズ性を選択基準にする必要があります。

npmのダウンロードトレンド

3 年

GitHub Starsランキング

統計詳細

パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
react-image-gallery312,8213,938123 kB143ヶ月前MIT
react-alice-carousel085195.7 kB92年前MIT
react-responsive-carousel02,676188 kB8-MIT
react-slick011,924775 kB49110ヶ月前MIT

React 用カルーセルライブラリ:性能、機能、アーキテクチャの比較

react-alice-carouselreact-image-galleryreact-responsive-carouselreact-slick は、React アプリケーションでスライドショーやカルーセルを実装するための主要なライブラリですが、内部構造と得意分野が異なります。それぞれの違いを理解し、プロジェクトに最適な選択をするために、技術的な観点から比較します。

📦 インストールと依存関係

ライブラリの選定では、依存関係の重さと CSS の扱いが重要です。外部ライブラリに依存しすぎると、バンドルサイズが増えたり、スタイルの競合が起きたりします。

react-slick は、元の jQuery プラグインである slick-carousel に依存しています。

  • CSS ファイルの明示的なインポートが必要です。
  • 環境によっては jQuery 関連の問題が発生する可能性があります。
// react-slick
import Slider from "react-slick";
import "slick-carousel/slick/slick.css";
import "slick-carousel/slick/slick-theme.css";

function App() {
  return <Slider>{items}</Slider>;
}

react-responsive-carousel は依存関係が少なく、独自の CSS をインポートします。

  • 軽量で、外部ライブラリへの依存がありません。
  • CSS モジュールや styled-components との相性が良いです。
// react-responsive-carousel
import { Carousel } from 'react-responsive-carousel';
import "react-responsive-carousel/lib/styles/carousel.min.css";

function App() {
  return <Carousel>{items}</Carousel>;
}

react-image-gallery は画像表示に特化しており、独自のスタイルシートが必要です。

  • 画像ギャラリー機能に特化した CSS が含まれています。
  • ライトボックス機能などもこの依存関係に含まれます。
// react-image-gallery
import ImageGallery from 'react-image-gallery';
import "react-image-gallery/styles/css/image-gallery.css";

function App() {
  return <ImageGallery items={items} />;
}

react-alice-carousel は純粋な React 実装に近いです。

  • 追加の CSS フレームワーク依存はありません。
  • カスタムスタイルの適用が容易です。
// react-alice-carousel
import AliceCarousel from 'react-alice-carousel';
import 'react-alice-carousel/lib/alice-carousel.css';

function App() {
  return <AliceCarousel>{items}</AliceCarousel>;
}

🛠️ 基本的な実装方法

各ライブラリは、データ構造とコンポーネントの使い方が異なります。特に、子要素の扱いと設定 props の違いに注意が必要です。

react-slick は設定オブジェクトを使って動作を制御します。

  • settings オブジェクトに矢印表示や autoplay などを定義します。
  • 子要素は直接 Slider コンポーネント内に配置します。
// react-slick
const settings = {
  dots: true,
  infinite: true,
  speed: 500,
  slidesToShow: 1
};

<Slider {...settings}>
  <div><h3>1</h3></div>
  <div><h3>2</h3></div>
</Slider>

react-responsive-carousel は props で機能をオンオフします。

  • 設定がフラットで直感的です。
  • 子要素は Carousel コンポーネント内に配置します。
// react-responsive-carousel
<Carousel showArrows={true} infiniteLoop={true}>
  <div><img src="1.jpg" /></div>
  <div><img src="2.jpg" /></div>
</Carousel>

react-image-gallery は専用のデータ構造を要求します。

  • items 配列にオブジェクトを渡す形式です。
  • 画像の URL や説明文をプロパティとして定義します。
// react-image-gallery
const items = [
  { original: "1.jpg", thumbnail: "1_thumb.jpg" },
  { original: "2.jpg", thumbnail: "2_thumb.jpg" }
];

<ImageGallery items={items} />

react-alice-carousel は子要素または items プロパティを使います。

  • responsive プロパティで挙動を制御できます。
  • 配列としてアイテムを渡すことも可能です。
// react-alice-carousel
const items = [
  <div>1</div>,
  <div>2</div>
];

<AliceCarousel items={items} disableDotsControls />

📱 レスポンシブ設定

モバイル対応では、画面サイズに応じて表示するアイテム数を変える必要があります。ここで各ライブラリの設計思想がはっきりと分かれます。

react-slickresponsive 配列でブレークポイントを定義します。

  • 特定の幅になったら設定を上書きできます。
  • 細かな制御が可能ですが、設定が複雑になりがちです。
// react-slick
const settings = {
  responsive: [
    {
      breakpoint: 1024,
      settings: { slidesToShow: 3 }
    },
    {
      breakpoint: 600,
      settings: { slidesToShow: 1 }
    }
  ]
};

react-responsive-carousel は CSS ベースの対応が基本です。

  • 組み込みのブレークポイント設定はありません。
  • 容器の幅に合わせて自動調整される仕組みです。
// react-responsive-carousel
// CSS で容器の幅を制御するのが一般的
<div style={{ width: '100%', maxWidth: '600px' }}>
  <Carousel>
    <div>Item 1</div>
  </Carousel>
</div>

react-image-gallery はギャラリー構造に最適化されています。

  • レスポンシブは主に画像のサイズ調整です。
  • 多列表示などの制御は限定的です。
// react-image-gallery
// 基本的には単一画像表示がメイン
<ImageGallery 
  items={items} 
  slideOnThumbnailOver={true} 
/>

react-alice-carousel はオブジェクト形式でレスポンシブを定義します。

  • ブレークポイントごとのアイテム数設定が明確です。
  • 設定が読みやすく、管理しやすいです。
// react-alice-carousel
const responsive = {
  0: { items: 1 },
  720: { items: 3 },
  1024: { items: 5 }
};

<AliceCarousel responsive={responsive} />

🌐 SSR サポート

Next.js などのサーバーサイドレンダリング環境では、window オブジェクトへのアクセスエラーに注意が必要です。

react-slick は SSR 設定に注意が必要です。

  • ssr: true を設定に含める必要があります。
  • 多くの場合、動的インポート(dynamic import)でラップします。
// react-slick (Next.js example)
const Slider = dynamic(() => import("react-slick"), { ssr: false });
// または settings に ssr: true を追加

react-responsive-carousel は SSR に強く設計されています。

  • 追加の設定なしで動作することが多いです。
  • サーバーとクライアントのハイドレーションミスマッチが少ないです。
// react-responsive-carousel
// 特別な SSR 設定は不要な場合が多い
<Carousel>
  <div>Content</div>
</Carousel>

react-image-gallery も SSR に対応しています。

  • 画像のプリロード処理などに配慮が必要です。
  • 標準的な構成で問題なく動作します。
// react-image-gallery
// 標準的に SSR 対応
<ImageGallery items={items} />

react-alice-carousel は SSR をサポートしています。

  • 初期レンダリング時のレイアウトシフトに注意します。
  • 設定で SSR 用のフラグを管理できる場合があります。
// react-alice-carousel
// SSR 環境でも動作するように設計されている
<AliceCarousel items={items} />

🖼️ 画像ギャラリー機能

画像を扱う場合、ライトボックスやサムネイル機能の有無が重要な分岐点になります。

react-slick は汎用カルーセルです。

  • ライトボックス機能は内置されていません。
  • 別途ライブラリを組み合わせる必要があります。
// react-slick
// ライトボックスには別のライブラリが必要
<Slider>
  <img src="photo.jpg" onClick={openLightbox} />
</Slider>

react-responsive-carousel も汎用カルーセルです。

  • 画像に特化した機能は最小限です。
  • シンプルなスライドショーに向いています。
// react-responsive-carousel
// 画像表示は可能だが機能はシンプル
<Carousel>
  <div><img src="photo.jpg" /></div>
</Carousel>

react-image-gallery はこの機能に特化しています。

  • クリックで拡大表示(ライトボックス)が標準装備です。
  • サムネイルナビゲーションも内置されています。
// react-image-gallery
// クリックで拡大表示が標準
<ImageGallery items={items} />

react-alice-carousel は汎用ですがカスタマイズ可能です。

  • ライトボックス機能は内置されていません。
  • 必要に応じてカスタム実装します。
// react-alice-carousel
// カスタム実装が必要
<AliceCarousel>
  <img src="photo.jpg" onClick={handleClick} />
</AliceCarousel>

📊 比較サマリー

特徴react-slickreact-responsive-carouselreact-image-galleryreact-alice-carousel
依存関係slick-carousel (CSS/JS)軽量 (独自 CSS)独自 CSS (画像特化)軽量 (独自 CSS)
SSR 対応設定必要 (dynamic import)良好良好良好
レスポンシブ配列で詳細設定CSS 依存画像サイズ調整オブジェクトで設定
画像機能汎用 (ライトボックス別)汎用 (シンプル)特化 (ライトボックス内蔵)汎用 (カスタマイズ可)
保守状況更新頻度は低め活発活発活発

💡 結論

react-slick は機能豊富ですが、依存関係と SSR 設定の重さを許容できる場合に限り検討します。既存の Slick デザインを維持したいレガシープロジェクト向きです。

react-responsive-carousel は、SSR を重視し、シンプルで軽量なカルーセルが必要な場合に最適です。余計な機能 없이 安定した動作を求めるときに選定します。

react-image-gallery は、画像専用のギャラリー(ライトボックス、サムネイル)が必要な場合に一択です。汎用カルーセルとして使おうとすると制限が多くなります。

react-alice-carousel は、モダンな React プロジェクトで、タッチ操作とレスポンシブ設定をバランスよく求めている場合に推奨します。設定が直感的で、カスタマイズもしやすいです。

最終的には、プロジェクトが「画像ギャラリー」を必要としているか、「汎用スライダー」を必要としているかで最初に絞り込み、その後に SSR やレスポンシブ要件で決定するのが賢明です。

選び方: react-image-gallery vs react-alice-carousel vs react-responsive-carousel vs react-slick

  • react-image-gallery:

    画像専用のギャラリー機能(サムネイル、ライトボックス、フルスクリーン表示)が必要な場合に選択します。一般的なコンテンツカルーセルではなく、写真ポートフォリオや製品画像表示に特化しています。追加のカスタマイズなしで高機能な画像表示を実現できます。

  • react-alice-carousel:

    タッチ操作への対応や細かいレスポンシブ制御が必要な場合に選択します。ブレークポイントに基づくアイテム数の変更が簡単で、モダンな React プロジェクトに適しています。依存関係が少なく、純粋な React 構成で動作させたいチームに向いています。

  • react-responsive-carousel:

    サーバーサイドレンダリング(SSR)を重視し、軽量なソリューションが必要な場合に選択します。設定がシンプルで、CSS によるカスタマイズが容易です。複雑な機能よりも安定性とパフォーマンスを優先するプロジェクトに適しています。

  • react-slick:

    豊富な機能と設定オプションが必要で、既存の Slick Carousel デザインを継承したい場合に選択します。ただし、jQuery 由来の CSS 依存関係があり、SSR 設定に追加の工夫が必要です。レガシーシステムからの移行や、多機能なスライダーが必要な場合に検討します。

react-image-gallery のREADME

React Image Gallery

A responsive, customizable image gallery component for React


npm version Download Count Bundle size CI TypeScript License: MIT


▶️ VIEW LIVE DEMO


React Image Gallery Demo


✨ Features

FeatureDescription
📱 Mobile SwipeNative touch gestures for smooth mobile navigation
🖼️ ThumbnailsCustomizable thumbnail navigation with multiple positions
📺 FullscreenBrowser fullscreen or CSS-based fullscreen modes
🎨 ThemingCSS custom properties for easy styling
⌨️ Keyboard NavArrow keys, escape, and custom key bindings
🔄 RTL SupportRight-to-left language support
↕️ Vertical ModeSlide vertically instead of horizontally
🎬 Custom SlidesRender videos, iframes, or any custom content

🚀 Getting Started

npm install react-image-gallery
import { useRef } from "react";
import ImageGallery from "react-image-gallery";
import "react-image-gallery/styles/image-gallery.css";
import type { GalleryItem, ImageGalleryRef } from "react-image-gallery";

const images: GalleryItem[] = [
  {
    original: "https://picsum.photos/id/1018/1000/600/",
    thumbnail: "https://picsum.photos/id/1018/250/150/",
  },
  {
    original: "https://picsum.photos/id/1015/1000/600/",
    thumbnail: "https://picsum.photos/id/1015/250/150/",
  },
  {
    original: "https://picsum.photos/id/1019/1000/600/",
    thumbnail: "https://picsum.photos/id/1019/250/150/",
  },
];

function MyGallery() {
  const galleryRef = useRef<ImageGalleryRef>(null);

  return (
    <ImageGallery
      ref={galleryRef}
      items={images}
      onSlide={(index) => console.log("Slid to", index)}
    />
  );
}

For more examples, see example/App.jsx


⚙️ Props

  • items: (required) Array of objects. Available properties:
    • original - image source URL
    • thumbnail - thumbnail source URL
    • fullscreen - fullscreen image URL (defaults to original)
    • originalHeight - image height (html5 attribute)
    • originalWidth - image width (html5 attribute)
    • loading - "lazy" or "eager" (HTML5 attribute)
    • thumbnailHeight - image height (html5 attribute)
    • thumbnailWidth - image width (html5 attribute)
    • thumbnailLoading - "lazy" or "eager" (HTML5 attribute)
    • originalClass - custom image class
    • thumbnailClass - custom thumbnail class
    • renderItem - Function for custom rendering a specific slide (see renderItem below)
    • renderThumbInner - Function for custom thumbnail renderer (see renderThumbInner below)
    • originalAlt - image alt
    • thumbnailAlt - thumbnail image alt
    • originalTitle - image title
    • thumbnailTitle - thumbnail image title
    • thumbnailLabel - label for thumbnail
    • description - description for image
    • srcSet - image srcset (html5 attribute)
    • sizes - image sizes (html5 attribute)
    • bulletClass - extra class for the bullet of the item
  • infinite: Boolean, default true - loop infinitely
  • lazyLoad: Boolean, default false
  • showNav: Boolean, default true
  • showThumbnails: Boolean, default true
  • thumbnailPosition: String, default bottom - options: top, right, bottom, left
  • showFullscreenButton: Boolean, default true
  • useBrowserFullscreen: Boolean, default true - if false, uses CSS-based fullscreen
  • useTranslate3D: Boolean, default true - if false, uses translate instead of translate3d
  • showPlayButton: Boolean, default true
  • isRTL: Boolean, default false - right-to-left mode
  • showBullets: Boolean, default false
  • maxBullets: Number, default undefined - max bullets shown (minimum 3, active bullet stays centered)
  • showIndex: Boolean, default false
  • autoPlay: Boolean, default false
  • disableThumbnailScroll: Boolean, default false - disable thumbnail auto-scroll
  • disableKeyDown: Boolean, default false - disable keyboard navigation
  • disableSwipe: Boolean, default false
  • disableThumbnailSwipe: Boolean, default false
  • onErrorImageURL: String, default undefined - fallback image URL for failed loads
  • indexSeparator: String, default ' / ', ignored if showIndex is false
  • slideDuration: Number, default 550 - slide transition duration (ms)
  • swipingTransitionDuration: Number, default 0 - transition duration while swiping (ms)
  • slideInterval: Number, default 3000
  • slideOnThumbnailOver: Boolean, default false
  • slideVertically: Boolean, default false - slide vertically instead of horizontally
  • flickThreshold: Number, default 0.4 - swipe velocity threshold (lower = more sensitive)
  • swipeThreshold: Number, default 30 - percentage of slide width needed to trigger navigation
  • stopPropagation: Boolean, default false - call stopPropagation on swipe events
  • startIndex: Number, default 0
  • onImageError: Function, callback(event) - overrides onErrorImageURL
  • onThumbnailError: Function, callback(event) - overrides onErrorImageURL
  • onThumbnailClick: Function, callback(event, index)
  • onBulletClick: Function, callback(event, index)
  • onImageLoad: Function, callback(event)
  • onSlide: Function, callback(currentIndex)
  • onBeforeSlide: Function, callback(nextIndex)
  • onScreenChange: Function, callback(isFullscreen)
  • onPause: Function, callback(currentIndex)
  • onPlay: Function, callback(currentIndex)
  • onClick: Function, callback(event)
  • onTouchMove: Function, callback(event) on gallery slide
  • onTouchEnd: Function, callback(event) on gallery slide
  • onTouchStart: Function, callback(event) on gallery slide
  • onMouseOver: Function, callback(event) on gallery slide
  • onMouseLeave: Function, callback(event) on gallery slide
  • additionalClass: String, additional class for the root node
  • renderCustomControls: Function, render custom controls on the current slide
  • renderItem: Function, custom slide rendering
  • renderThumbInner: Function, custom thumbnail rendering
  • renderLeftNav: Function, custom left nav component
  • renderRightNav: Function, custom right nav component
  • renderTopNav: Function, custom top nav component (vertical mode)
  • renderBottomNav: Function, custom bottom nav component (vertical mode)
  • renderPlayPauseButton: Function, custom play/pause button
  • renderFullscreenButton: Function, custom fullscreen button
  • useWindowKeyDown: Boolean, default true - use window or element for key events

🔧 Functions

The following functions can be accessed using refs

  • play(): starts the slideshow
  • pause(): pauses the slideshow
  • togglePlay(): toggles between play and pause
  • fullScreen(): enters fullscreen mode
  • exitFullScreen(): exits fullscreen mode
  • toggleFullScreen(): toggles fullscreen mode
  • slideToIndex(index): slides to a specific index
  • getCurrentIndex(): returns the current index

🤝 Contributing

Pull requests should be focused on a single issue. If you're unsure whether a change is useful or involves a major modification, please open an issue first.

  • Follow the eslint config
  • Comment your code

🛠️ Build the example locally

Requires Node.js >= 18.18

git clone https://github.com/xiaolin/react-image-gallery.git
cd react-image-gallery
npm install
npm start

Then open localhost:8001 in a browser.


📄 License

MIT © Xiao Lin