Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

143
Vistas
Is there a way to link my sort only when the checkbox is clicked

I am learning react and I am trying to sort and filter through a list to be displayed on a website. I created a sort function for example and used Formgroups for my checkboxes. I do not understand how I can link the checkboxes and make them work only when the boxes have been clicked on. `const [highestAmount, setHighestAmount] = useState(false); //make an empty list that then will be populated when the state changes

const [highestAmount, setHighestAmount] = useState(false);
        //make an empty list that then will be populated when the state changes

       const sortHighestAmount = list.sort(function (a, b) {
            return a.amount - b.amount;
        }).reverse();
      
        console.log(sortHighestAmount);



const [lowestAmount, setLowestAmount] = useState(false);

    const sortHighestAmount =  (event) => {
        console.log(event.target.value);
        const Highest = list.sort(function (a, b) {
        return a.amount - b.amount;
    });
  
    }

<FormControlLabel control={<Checkbox checked={highestAmount} onChange={(event) => setHighestAmount(event.target.checked)} inputProps={{ 'aria-label': 'controlled' }} />} label="Highest Amount" />

        <FormControlLabel control={<Checkbox
            checked={lowestAmount}
            onChange={(event) => setLowestAmount(event.target.checked)}
            inputProps={{ 'aria-label': 'controlled' }}
        />} label="Lowest Amount" />

`

I am trying to filter through a list. I have written a sort code, but I am finding it a bit challenging to do a useHandle state or any other hook that can help me sort through the list.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda