Home > Back-end >  react-input-range library in React
react-input-range library in React

Time:03-31

I am trying to create a Range bar like this

enter image description here

using react-input-range

but when writing this code

import InputRange from 'react-input-range';
import 'react-input-range/lib/css/index.css';

<form action="">
  <InputRange
      maxValue={100}
      minValue={0}
      formatLabel={value => `$${value}`}
      value={range}
      onChange={value => setRange(value)}
      onChangeComplete={value => console.log(value)}
    />
</form>

I got this

enter image description here

CodePudding user response:

Set the initial value of range(state) and you are good to go.

const [range, setRange ]= useState({
        min: 5,
        max: 10,
      });
    <form action="">
      <InputRange
          maxValue={100}
          minValue={0}
          formatLabel={value => `$${value}`}
          value={range}
          onChange={value => setRange(value)}
          onChangeComplete={value => console.log(value)}
        />
    </form>
  • Related