Registry / web-framework / react-slider

react-slider

JSON →
library2.0.6jsnpmunverified

react-slider is an actively maintained React component designed for creating highly customizable range sliders. The current stable version is 2.0.6, with recent updates focusing on stability and compatibility across modern web environments. It supports both single and multiple handles, offers horizontal and vertical orientations, and includes accessibility features through props like `ariaLabel` and `ariaValuetext`. Key differentiators include built-in `ResizeObserver` support for dynamic slider resizing and a commitment to broad React compatibility, explicitly listing React 16, 17, and 18 as peer dependencies. The project demonstrates a consistent release cadence, regularly publishing patch updates for bug fixes and minor enhancements, with major versions introducing significant features and occasional breaking changes. It addresses common slider challenges such as mobile 'snap back' behavior and module resolution issues for modern JavaScript module systems.

npm install react-slider
INSTALL
IMPORT
SIG · REACT-SLIDER
R
react-slider
web-frameworkjavascriptv2.0.6
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.

Slider
import Slider from 'react-slider';
import { Slider } from 'react-slider';
The primary `Slider` component is exported as the default export of the package. Using a named import will result in runtime errors.
Slider (CommonJS)
const Slider = require('react-slider');
For CommonJS environments, typical in Node.js applications or older bundler configurations. This correctly imports the default export.
TypeScript Type Definitions
import Slider from 'react-slider'; import type { SliderProps } from 'react-slider';
While the `react-slider` package generally infers types well, you may explicitly import `SliderProps` for type-checking when extending or deeply configuring the component.

This quickstart demonstrates both single-handle and dual-handle (range) sliders with custom thumb and track rendering. It shows how to manage slider state using React hooks and includes basic inline styles for clarity and immediate visual feedback.

import React from 'react'; import ReactDOM from 'react-dom/client'; import Slider from 'react-slider'; // Basic inline styles for demonstration. In a real app, use CSS classes. const thumbStyle = { height: '25px', width: '25px', backgroundColor: '#555', borderRadius: '50%', cursor: 'grab', display: 'flex', justifyContent: 'center', alignItems: 'center', color: '#fff', fontSize: '0.8em' }; const trackStyle = (state, props) => ({ top: '0', bottom: '0', background: props.index === 1 ? '#ddd' : '#007bff', borderRadius: '5px' }); const sliderContainerStyle = { width: '80%', margin: '50px auto', height: '25px', background: '#eee', borderRadius: '5px', display: 'flex', alignItems: 'center', }; function App() { const [value, setValue] = React.useState(50); const [rangeValues, setRangeValues] = React.useState([25, 75]); return ( <div style={{ fontFamily: 'sans-serif', textAlign: 'center' }}> <h1>React Slider Examples</h1> <h2>Single Handle Slider</h2> <div style={sliderContainerStyle}> <Slider value={value} onChange={setValue} renderTrack={(props, state) => <div {...props} style={trackStyle(state, props)} />} renderThumb={(props, state) => <div {...props} style={thumbStyle}>{state.valueNow}</div>} min={0} max={100} step={1} ariaLabel="Single value slider" /> </div> <p>Current Value: {value}</p> <h2>Range Slider</h2> <div style={sliderContainerStyle}> <Slider value={rangeValues} onChange={setRangeValues} renderTrack={(props, state) => <div {...props} style={trackStyle(state, props)} />} renderThumb={(props, state) => <div {...props} style={thumbStyle}>{state.valueNow}</div>} min={0} max={100} step={1} ariaLabel={['Min value slider', 'Max value slider']} pearling minDistance={10} /> </div> <p>Current Range: [{rangeValues[0]}, {rangeValues[1]}]</p> </div> ); } const root = ReactDOM.createRoot(document.getElementById('root') ?? document.createElement('div')); root.render(<App />);
Debug
Known issues
breakingVersion 2.0.0 introduced a breaking change related to updating `create-react-styleguide` to v8.x. While primarily an internal build system dependency, this might affect custom development setups or build processes that rely on specific versions or outputs from the internal style guide tooling.
fix
Review your project's build pipeline and development environment configurations. If encountering issues after upgrading to v2.x, consult the `react-slider` changelog or GitHub issues for potential migration guidance related to build tooling.
affects: >=2.0.0
gotcha`react-slider` versions 2.0.0 onwards leverage dual package extensions, which can sometimes lead to module resolution issues in older tooling or mixed CommonJS/ESM projects. Early v2.x patch releases specifically addressed 'module resolution' and 'dual package extensions' bugs.
fix
Ensure your project's build configuration (Webpack, Rollup, Vite) and `tsconfig.json` (for TypeScript) are correctly set up to handle ESM and dual package resolutions. Consider `"type": "module"` in your `package.json` for ESM projects or `"moduleResolution": "bundler"` in TypeScript 5+ for improved compatibility. Upgrade your bundler and Node.js versions if issues persist.
affects: >=2.0.0
gotchaPrior to v2.0.5, users reported a 'snap back' issue where slider handles on mobile devices would occasionally revert to a previous position during interaction, creating a frustrating user experience.
fix
Upgrade to `react-slider@2.0.5` or a later version to ensure this specific mobile interaction bug is resolved and benefit from improved touch handling.
affects: <2.0.5
gotchaOlder versions (pre-v0.11.2) had known issues with React ref compatibility for React 16+ and a bug where the slider value could incorrectly become `NaN`. These issues can lead to unexpected behavior or runtime errors.
fix
Upgrade `react-slider` to version `0.11.2` or higher to ensure compatibility with modern React ref syntax and prevent the `NaN` value bug.
affects: <0.11.2
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'call')
This error specifically occurred in `react-slider@0.11.2` after a brief introduction of arrow functions that broke some older build environments or transpilation setups.
fix
If you are specifically on `react-slider@0.11.2`, downgrade to `0.11.1` or upgrade to `0.11.3` (or higher) which reverted the problematic arrow functions to ES5 syntax for broader compatibility.
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components)...Check the render method of `App`.
This common React error indicates that you are likely attempting to import `Slider` as a named export, but `react-slider` provides it as a default export.
fix
Change your import statement from `import { Slider } from 'react-slider';` to the correct default import: `import Slider from 'react-slider';`
Invariant Violation: Min and Max values for `react-slider` must be numbers.
The `min`, `max`, `value`, or `defaultValue` props passed to the `Slider` component are not strictly numbers. This often happens if values are read from inputs as strings or are `undefined`.
fix
Ensure that all value-related props (`min`, `max`, `value`, `defaultValue`) are explicitly numeric types. Use `parseInt()`, `parseFloat()`, or the unary plus operator (`+`) to convert string inputs to numbers.
Module not found: Can't resolve 'react-slider' in '...' OR Failed to compile: Can't resolve 'react-slider/dist/...' for CommonJS
These errors typically point to module resolution issues, especially in `react-slider` v2.x due to its dual package extensions and how bundlers resolve ESM vs CommonJS paths.
fix
Verify your bundler (Webpack, Rollup, Vite) configuration correctly handles ESM/CJS interoperability. For TypeScript, ensure `tsconfig.json` has `"moduleResolution": "bundler"` (TypeScript 5+) or `"node"`/`"nodenext"` (for older TS). Clear your `node_modules` and `package-lock.json`/`yarn.lock` and reinstall dependencies.
Upgrade
Version history
2.0.6latest on npm
Audit
Dependencies
reactrequiredPeer dependency for rendering the component. Requires React 16, 17, or 18.
Agent activity
4 hits · last 30 days
node
4
Resources
react-slider — npm install react-slider · libregistry