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

144
Visualizações
How can we do deep comparison of "this.props" and "nextProps" in "shouldComponentUpdate"?

So far, what I'm aware is, if the props (current and next) and stringified and then compared, it might provide some result. But, I'm not sure if that works correctly for props which are holding functions. If there is any other possible way to do so, please explain.

JSON.stringify(this.props) === JSON.stringify(nextProps)

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

0

JSON.stringify may not work because object keys order is based on when they are defined (relevant stackoverflow rabbit hole). So you may not always be able to guarantee they will be in the same order.

For reasons that I can't remember (possibly boredom) I made an object diff function a few months ago:

function diff (a, b) {
  let obj = {};
  
  for (let key in a) {
    if (a[key] === b[key]) continue;
    
    obj[key] = b[key];
  }
  
  for (let key in b) {
    if (key in obj) continue;
    
    if (a[key] === b[key]) continue;
    
    obj[key] = b[key];
  }
  
  return obj;
}

Though this will only work for primitive values (e.g. string, number, etc...).

If this is a personal project, why not try and extend this for objects and arrays?

If not, I'd suggest using a library like deep-object-diff

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