Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

91
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!