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

73
Views
Materializar el control deslizante en la clase React

Tengo un control deslizante actualmente trabajando en un componente de función de reacción. Me pregunto cómo puedo implementar el control deslizante a continuación correctamente en un componente de clase React.

 import * as React from 'react'; import Box from '@mui/material/Box'; import Slider from '@mui/material/Slider'; function valuetext(value) { return `${value}°C`; } export default function RangeSlider() { const [value, setValue] = React.useState([20, 37]); const handleChange = (event, newValue) => { setValue(newValue); }; return ( <Box sx={{ width: 300 }}> <br /><br /> <Slider getAriaLabel={() => 'Temperature range'} value={value} onChange={handleChange} valueLabelDisplay="on" getAriaValueText={valuetext} /> </Box> ); }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Centrado en los componentes de clase, tendrás que:

  • use this.state en lugar de React.useState
  • Deberá usar el constructor (y vincular la función handleChange )
  • Eso es todo

Tiene un entorno limitado de código funcionando aquí: https://codesandbox.io/s/clever-wildflower-kzjck?file=/src/ClassSlider.js

Sería como:

 function valuetext(value) { return `${value}°C`; } class ClassComponent extends React.Component { constructor(props) { super(props); this.state = { value: [20, 37] }; this.handleChange = this.handleChange.bind(this); } handleChange(event, newValue) { this.setState({ value: newValue }); } render() { return ( <Box sx={{ width: 300 }}> <br /> <br /> <Slider getAriaLabel={() => "Temperature range"} value={this.state.value} onChange={this.handleChange} valueLabelDisplay="on" getAriaValueText={valuetext} /> </Box> ); } } export default ClassComponent;
about 4 years ago · Juan Pablo Isaza Report

0

const minDistance = 10; export default function MinimumDistanceSlider() { const [value, setValue] = React.useState([20, 37]); const handleChange1 = (event, newValue, activeThumb) => { if (!Array.isArray(newValue)) { return; } if (activeThumb === 0) { setValue([Math.min(newValue[0], value[1] - minDistance), value[1]]); } else { setValue([value1[0], Math.max(newValue[1], value[0] + minDistance)]); } };

prueba esto

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!