React Slider - Overview
The Slider is a UI component that allows an end user to set a numeric value on a continuous range of possible values.
The following code adds a simple Slider to your page. The min and max properties limit the range of accepted values. The value sets the initial value for the UI component.
Code
- import React, { useCallback, useState } from 'react';
- import 'devextreme/dist/css/dx.fluent.blue.light.css';
- import { Slider, type SliderTypes } from 'devextreme-react/slider';
- function App() {
- const [value, setValue] = useState<number>(25);
- const handleValueChange = useCallback((e: SliderTypes.ValueChangedEvent) => {
- const previousValue = e.previousValue;
- const newValue = e.value;
- // Event handling commands go here
- setValue(newValue);
- }, []);
- return (
- <Slider
- min={0}
- max={100}
- value={value}
- onValueChanged={handleValueChange}
- />
- );
- }
- export default App;
In addition, you can specify the step of Slider values using the step property.
Code
- import React, { useCallback, useState } from 'react';
- import 'devextreme/dist/css/dx.fluent.blue.light.css';
- import { Slider, type SliderTypes } from 'devextreme-react/slider';
- function App() {
- const [value, setValue] = useState<number>(25);
- const handleValueChange = useCallback((e: SliderTypes.ValueChangedEvent) => {
- const previousValue = e.previousValue;
- const newValue = e.value;
- // Event handling commands go here
- setValue(newValue);
- }, []);
- return (
- <Slider
- min={0}
- max={100}
- step={10}
- value={value}
- onValueChanged={handleValueChange}
- />
- );
- }
- export default App;