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

134
Visualizações
React adding to array performance with useState vs push

When I add elements to an array and want to lead to a render of components using that array, I have to use the useState hook and the spread operator, if I'm not mistaken:

setTestArray(array => [...array, data]);

When I want to add an element in normal JavaScript, I just use push. Isn't it much faster to just push an element to an array? Isn't there a way to avoid this problem and e.g. push an element and then "say to React" that you want the components using that array to rerender? Are there any other ways to add elements to an array/set that have a better performance?

Just getting started with react, so maybe I have overlooked something here :/

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

React states are immutable, so if you want to change state you have to set the state again. I'm sure under the hood, react does some smart diffing that is able to re-render things smartly.

about 4 years ago · Juan Pablo Isaza Relatório
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