Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
R

react-id-swiper

> 前端框架
Open source

A library to use idangerous Swiper as a ReactJs component which allows Swiper's modules custom build

1.5K stars0 likes2 views
WebsiteGitHub

About

A library to use idangerous Swiper as a ReactJs component which allows Swiper's modules custom build

react-id-swiper ( Newest version 4.0.0 )

A library to use Swiper as a ReactJs component

What is Swiper?

Swiper - is the free and most modern mobile touch slider with hardware accelerated transitions and amazing native behavior.

It is intended to be used in mobile websites, mobile web apps, and mobile native/hybrid apps. Designed mostly for iOS, but also works great on latest Android, Windows Phone 8 and modern Desktop browsers.

Swiper is not compatible with all platforms, it is a modern touch slider which is focused only on modern apps/platforms to bring the best experience and simplicity. Swiper does work well with Gatsby.

Props

Name Type Default value Description
ContainerEl String 'div' Element type for container
containerClass String swiper-container Swiper container class name
WrapperEl String 'div' Element type for wrapper
wrapperClass String swiper-wrapper Swiper wrapper class name
slideClass String swiper-slide Swiper slide class name
shouldSwiperUpdate Boolean false Update swiper when component is updated
rebuildOnUpdate Boolean false Rebuild swiper when component is updated
noSwiping Boolean false Disable swiping by condition
activeSlideKey String null Initial slide index
renderPrevButton function Render props function for prev button
renderNextButton function Render props function for next button
renderScrollbar function Render props function for scrollbar
renderPagination function Render props function for pagination
renderParallax function Render props function for parallax

If you want to use Swiper custom build to reduce bundle size, you need to use extra props below.

Custom build extra props

Name Type Default value Description
Swiper Class Swiper class
modules array Array of Swiper necessary modules

NOTE:

  • You can also use Swiper's original params too. Swiper API documentation HERE
  • Find more info about Swiper custom build HERE
  • <= 3.x documentation

Documentation

  • Get Started
  • API
  • Custom Build
  • Examples

Installation and setup

  • From version 2.0.0, it requires React & ReactDOM ver >=16.8.0 to use Hooks
  • From version 2.4.0, it requires Swiper ver >= 5.0.0

Npm package

By npm

bash
npm install --save react-id-swiper@latest swiper@latest

By Yarn

bash
yarn add react-id-swiper@latest swiper@latest

CDN

xml
<script src="https://unpkg.com/[email protected]/lib/react-id-swiper.js"></script>
xml
<script src="https://unpkg.com/[email protected]/lib/react-id-swiper.min.js"></script>

Styling

Swiper stylesheet file is required

Use Swiper stylesheet file from CDN

xml
<link rel="stylesheet" href="https://unpkg.com/swiper/css/swiper.css">
xml
<link rel="stylesheet" href="https://unpkg.com/swiper/css/swiper.min.css">

Or from Swiper package

You should import directly from Swiper package which supports css, scss and less

css

javascript
import 'swiper/css/swiper.css'

scss

javascript
import 'swiper/swiper.scss'

less

javascript
import 'swiper/swiper.less'

Examples

Live Examples

Codesandbox Live Examples

Default

javascript
import React from 'react';
import Swiper from 'react-id-swiper';
import 'swiper/css/swiper.css';

const SimpleSwiper = () => (
  <Swiper>
    

    

    

    

    

  </Swiper>
)

export default SimpleSwiper;

Using params

javascript
import React from 'react';
import Swiper from 'react-id-swiper';

const SimpleSwiperWithParams = () => {
  const params = {
    pagination: {
      el: '.swiper-pagination',
      type: 'bullets',
      clickable: true
    },
    navigation: {
      nextEl: '.swiper-button-next',
      prevEl: '.swiper-button-prev'
    },
    spaceBetween: 30
  }

  return(
    <Swiper {...params}>
      

      

      

      

      

    </Swiper>
  )
}

export default SimpleSwiperWithParams;

Manipulating swiper from outside swiper component

…

Custom build Swiper

You can find the WORKING DEMO REPO HERE

…

NOTE:

  • If you use Webpack & Babel you need to setup Babel loader config in webpack.config.js like below:
javascript
module: {
  rules: [
    {
      exclude: [/node_modules\/(?!(swiper|dom7)\/).*/, /\.test\.js(x)?$/],
      test: /\.js(x)?$/,
      use: [{ loader: 'babel-loader' }],
    }
  ],
}

Adding customized css classes

javascript
const params = {
  pagination: {
    el: '.swiper-pagination.customized-swiper-pagination',
  }, // Add your class name for pagination container
  navigation: {
    nextEl: '.swiper-button-next.customized-swiper-button-next', // Add your class name for next button
    prevEl: '.swiper-button-prev.customized-swiper-button-prev' // Add your class name for prev button
  },
  containerClass: 'customized-swiper-container' // Replace swiper-container with customized-swiper-container
}

Adding customized components

For customized rendering to work, you have to use same classname with params el.

javascript
const params = {
  navigation: {
    nextEl: '.swiper-button-next',
    prevEl: '.swiper-button-prev'
  },
  renderPrevButton: () => <button className="swiper-button-prev">Prev</button>,
  renderNextButton: () => <button className="swiper-button-next">Next</button>,
}

Workable slides

Each slide should be wrapped by HTML element

BAD CODE :thumbsdown:

javascript
<Swiper {...params}>
  Slide content
</Swiper>

GOOD CODE :thumbsup:

javascript
<Swiper {...params}>
  <span>Slide content</span>
</Swiper>

Bug report

Please use the prepared Codesanbox below to reproduce your issue. Thank you!!

Authors

  • Asher Nguyen - Initial work - Asher Nguyen

See also the list of contributors who participated in this project.

Buy me a coffee

License

This project is licensed under the MIT License - see the LICENSE file for details

Issues· 108 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

JavaScriptidangerousreact-carouselreact-id-swiperreact-native-swiper

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category前端框架
PricingOpen source

> Related tools

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架