Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

142
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda