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

147
Visualizações
Component List do no re render when having key

I have an array of strings that look like this

['sass', 'css', 'daniel', 'javascript', 'figma', 'html', 'git', 'react', 'blank']

It is in state and I pass the array to a child component as props, to iterate it and create a list, that is displayed inside a board of items

[ 1 , 2 , 3]

[ 4 , 5 , 6]

[ 7 , 8 , 9]

. When I click a button the array is mixed up with the same elements and passed again to props

const SlidePuzzle = ({puzzleItems}) => {
return (
    <div className="slidePuzzleContainer">
        {puzzleItems.map((item, index) => {
            return <PuzzleItem item={item}  key={index} />;
        })}
    </div>
)};

I thought the list of items was not re rendering when props changed. But they were indeed, and changed their order in the DOM. Just that they kept their previous position in the board. I solve this by removing the key or setting it to the index of the array (that I know is not the best). Could you please explain why this happens and if there's a better way to solve this ? Thank you so much..... :)

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