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

176
Visualizações
React.memo large array of nested objects, proposed way of making comparison efficient, using change tracking id

i have a react component that takes an array of complex objects and does some expensive computation with them.

I want to use React.memo to avoid re rendering if the arrays have not changed.

deep compare may be expensive.

i have thought of a way of checking if the array has changed and am wondering why i cant find any examples of people using the method, as it seems like such a simple solution.

perhaps i am missing a reason why i shouldnt use the method?

is this a commonly used technique?

i know i can JSON.stringify the objects then compare them, is that not potentially expensive if the objects are large?

i want to change a unique id field on the object any time any of the values in the object changes

e.g.

const arrayOfLargeObjects = [obj1,obj2,obj3,.....and so on]

if 

obj1 = {letter: a, moreNestedStuff: {blah blah},memoizationid: '1'}//id is longer in actual implementation

changes to 

obj1 = {letter: b, moreNestedStuff: {blah blah},memoizationid: '2'}

//this is all done imutabily details left out for brevity

const stringify = (obj)=>obj.map(el.memoizationid).join('')

const comparisonFunction = (a,b)=>stringify(a)===stringify(b)

<MyComponent myArray={arrayOfLargeObjects}/>

React.memo(MyComponent, comparisonFunction);
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