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

147
Views
Linter complains about empty dependency array in React Native hooks

In a React Native useEffect it is acceptable to use an empty dependency array (and this is often done intentionally for legitimate reasons).

In useEffect, what's the difference between providing no dependency array and an empty one?

Yet Linter keeps complaining and suggesting to either add certain parameters as elements of the dependency array or to remove it. Removing the dependency array is not an option for me. Should I accept the Linter suggestion and add a long list of items to the dependency array? Or is there an easy way I change the Linter settings?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

AFAIK there's no configuration to the react-hooks/exhaustive-deps linting rule, but you can ignore the eslint rule for a specific line.

If you truly want the effect to run only once exactly when the component mounts then you are correct to use an empty dependency array. You can disable the eslint rule for that line to ignore it.

useEffect(() => {
  ... business logic ...

  // NOTE: Run effect once on component mount, please
  // recheck dependencies if effect is updated.
  // eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

Note: If you later update the effect and it needs to run after other dependencies then this disabled comment can potentially mask future bugs, so I suggest leaving a rather overt comment as for the reason to override the established linting rule.

about 4 years ago · Juan Pablo Isaza Report

0

Usually what linter suggests (adding the dependencies) is the best solution for it, since usually you'll want to re-run the effect when some of those variables used in the effect change. See https://typeofnan.dev/you-probably-shouldnt-ignore-react-hooks-exhaustive-deps-warnings/ for more info. Also it has been discussed here: https://github.com/facebook/react/issues/14920

about 4 years ago · Juan Pablo Isaza Report
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!