Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

93
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda