Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

132
Views
create a custum range in react js

enter image description here

i am trying to make a range selector like this can anyone help


import React, { Component } from "react";



const [selectedValue, setSelectedValue] = useState(0);


const handleChange = (e) => {
    setSelectedValue(e.target.value);
  
  };


  render() {
    return (
      <div>
        <input
            onInput={handleChange}
            type="range"
            min="0"
            value={selectedValue}
            max="5"
            step="1"
            list="tick-list"
          />
      </div>
    );
  }
}

ihave mananged the working part of this deign i just want the cssto like that

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Please see working version below.

First thing to note is that you should use react state to manage the value of the the slider - regardless of how often you want to interact with it.

A nice way to get the steps of ten is divide the current value by 10, round it up to the nearest integer, and multiply it by 10 again. Note that you should not mutate the actual sliderValue variable but should rather use a new variable. This method was used in example 1.

const shownValue = Math.round(sliderValue / 10) * 10

If you would like to only have the slider jump in large steps (example 2) then you should just set the max attribute on the slider input to 6 and multiply the result by 10.

const {useState} = React;

const Example1 = () => {
  const [sliderValue, setSliderValue] = useState(0);
  const shownValue = Math.round(sliderValue / 10) * 10
  
     return (
      <div>
        <h3>
        Example 1 - smooth
        </h3>
        <div>
          <input
            type="range"
            name="range"
            id="range"
            min="0"
            max="60"
            value={sliderValue}
            onChange={e => {
            setSliderValue(e.target.value);
            }}
          />
        </div>
        <div>
          {shownValue}
        </div>
      </div>
   );
};

const Example2 = () => {
  const [sliderValue, setSliderValue] = useState(0);
  
     return (
      <div>
        <h3>
        Example 2 - incremental
        </h3>
        <div>
          <input
            type="range"
            name="range"
            id="range"
            min="0"
            max="6"
            value={sliderValue}
            onChange={e => {
            setSliderValue(e.target.value);
            }}
          />
        </div>
        <div>
          {sliderValue * 10}
        </div>
      </div>
   );
};

// Render it
ReactDOM.render(
  <div>
    <Example1 />
    <Example2 />
  </div>,
  document.getElementById("react")
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.1/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.1/umd/react-dom.production.min.js"></script>
<div id="react"></div>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!