0.0.7 • Public • Published

dub-step 🕺🏽
dub-step logo

A set of primitives for building step/index based UI widgets controlled by swipe, timers, and/or buttons.

Travis npm GitHub Issues Coverage Styled with Prettier README generated by emdaer
Twitter GitHub stars

Many existing carousel/swipe solutions in one way or another end up dictating the markup of your UI. They expose many options to allow for extensibility, but this results in a convoluted API that is not flexible. In these cases, your often very specific design must be fit into an existing rigid solution.

dub-step simply manages the state needed to power a carousel, slideshow, photo gallery, or even multi-step forms, allowing you to build the UI how you want. It uses the function as child and "prop getter" patterns, which gives you maximum flexibility with a minimal API.

NOTE: Version v0.0.5 introduced a breaking change. All occurences of index in the dub-step API were renamed to step, for consistency. Please see the release notes for more info.

Table of Contents


This module is distributed via npm which is bundled with node and should be installed as one of your project's dependencies:

npm install --save dub-step

This package also depends on react and prop-types. Please make sure you have those installed as well.


NOTE: Glamorous is used for styles in this example, but is not required.

import DubStep from 'dub-step';
import glamorous, { Div, Img } from 'glamorous';
function BasicSlideshow({slides, onChange}) {
  return (
      }) => (
          <Div width="350px" overflow="hidden" margin="0 auto">
              transform={`translate3d(${-step * 350}px, 0, 0)`}
              transition="all .3s ease-in-out"
              {slides.map((url, i) => <Img src={url} alt="doge pic" width="100%" height="100%" />)}
          <Div display="flex" justifyContent="center">
            {slides.map((url, i) => (
                border={=== step ? '1px solid darkgray' : 'none'}
                transform={`scale(${=== step ? 1.2 : 1})`}
          <Div display="flex" justifyContent="center">
const DOGE_PICS = [
function App() {
  return (
      onChange={currentIndex => console.log(currentIndex)}


In the example of above, the step is used in coordination with a css transform/transition to animate the changing slides.


See the API Docs for information on the props exposed by this package.

Control Props

dub-step manages its own state internally and calls your onChange/OnPlay/OnPause etc. handlers with any relevant changes. The controllable state that dub-step manages includes: step and paused. Your child callback function (read more below) can be used to manipulate this state from within the render function and can likely support many of your use cases.

However, if more control is needed, you can pass any of these pieces of state as a prop (as indicated above) and that state becomes controlled. As soon as this.props[controllableStatePropKey] !== undefined, internally, dub-step will determine its state based on your prop's value rather than its own internal state. You will be required to keep the state up to date, but you can also control the state from anywhere, be that state from other components, redux, react-router, or anywhere else.

How To Render

Dub step uses the child callback render function pattern. This is where you render whatever you want to based on the state of dub-step which is passed to the callback as parameters. The function is passed as the child prop of the DubStep component:

  {({/* parameters here */}) => (/* your render code here*/)}

The paramters of this function can be split into three categories: State, Components, and Actions.

See the API Docs for a list of these properties.


These are not yet available on github. But check out the codesandbox until they are! Fork it and build your own examples then tweet me about it!

Edit dub-step Examples 🕺🏽

Here are some of the existing examples:


Kent Dodds' work on downshift 🏎 heavily inspired this package. You may even notice some copy pasta in the README 😏.

This package is also inspired by work I rubber-ducked with flip for managing focus in a TV Shelf UI.

Much of the swipe code was lifted from react-slick by akiran a very solid solution for swipe friendly carousels.

There is no lack of carousel libraries out there. I looked at many of them while writting this package. I hope dub-step represents a move towards an unopinionated solution that enables design and development to work together not against each other.

Check out other solutions on npm.

Some of the time spent writting this package was sponsored by Four Kitchens. I ❤️ 4K. Come work with us!

Four Kitchens logo


If you'd like to make emdaer better, please read our guide to contributing.

These wonderful people have contributed to dub-step in one way or another:

Luke Herrington

Connor Bär


Kent C. Dodds


dub-step is MIT licensed.


DownloadsWeekly Downloads






Last publish


  • infiniteluke