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

92
Visualizações
Custom hook that keeps track of changed objects

I wrote a custom hook (I call it useChanges) in React that is expected to keep track of changed objects. It takes three parameters (initial array of changed objects, original array of objects, a selector function that selects a property of the object that has a unique value among the other objects).

See the working example here: https://codesandbox.io/s/compassionate-murdock-ey8zx

The way the custom hook is used is with a form that has one input and one textarea (controlled components). Whenever a user types into an input or into a textarea the values are stored in state. Additionally, I use debouncing functionality for the whole form state and whenever debounced form values change I have a block of code inside useEffect that runs. In this block of code I call a function applyChanges which is provided by the custom hook.

The problem is when I include all suggested dependencies to the useEffect. At the moment I have only debouncedValues in the dependency array. However ESLint tells me to also include getChangedItemAndOriginalItem function and applyChanges function. If I include them it results in an infinite loop and the component never stops re-rendering.

I have tried to memoize both the functions in the custom hook but it did not help as ESLint rule complained about missing dependencies in the custom hook.

Is there a way to change my code in a way so that I can make ESLint happy?

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