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

96
Visualizações
React not rendering items according to the sorting

I want to render my items according to the sorting but I don't know why it is not rendering items accordingly. When I console the values so it shows correctly, and when I checked the data-order so it shows the output like 1, 3, 2

constructor(props) {
    super(props)
    this.state = {
        properties: [
            {
                order: 3,
                title: "Title 3",
                type: "checkbox"
            },
            {
                order: 1,
                title: "Title 1",
                type: "string"
            },
            {
                order: 5,
                title: "Title 5",
                type: "number"
            },
            {
                order: 2,
                title: "Title 2",
                type: 'checkbox'
            }
        ]
    }
}

render() {
    return (
        [...this.state.properties].sort((a, b) =>  (a.order > b.order) ? 1 : -1).map((item, key) => {
            switch(item.type) {
                case "string":
                    return <StringComponent data-order={item.order} {...item} />;
                case "number":
                    return <NumberComponent data-order={item.order} {...item} />;
                case "checkbox":
                    return <CheckboxComponent data-order={item.order} {...item} />;
            }
        })
    )
}

output:

<div data-order="1"></div>
<div data-order="5"></div>
<div data-order="3"></div>
<div data-order="2"></div>

when I console the value so the output is:

[
    {
        order: 1,
        title: "Title 1",
        type: "string"
    },
    {
        order: 2,
        title: "Title 2",
        type: 'checkbox'
    }
    {
        order: 3,
        title: "Title 3",
        type: "checkbox"
    },
    {
        order: 5,
        title: "Title 5",
        type: "number"
    },
]
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