Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

"This hook do not specify all of its dependencies." but for function defined OUTSIDE of the component function body #4142

Open
1 task done
peter-goodfill opened this issue Jan 5, 2023 · 2 comments
Labels
A-Linter Area: linter S-Bug: confirmed Status: report has been confirmed as a valid bug

Comments

@peter-goodfill
Copy link

peter-goodfill commented Jan 5, 2023

Environment information

When I run this command I got insanely long output full of code.

I have this version of rome:

rome@^11:
  version "11.0.0"
  resolved "https://registry.yarnpkg.com/rome/-/rome-11.0.0.tgz#cd2f00fadfd3611399eba9a2f87612e1f3299a23"

What happened?

I have a function that is outside of the component function body:

const dayToYyyymmdd = (d: Date) => d.toJSON().substring(0, 10); // <---- THIS


export const Calendar: React.FC<CalendarProps> = ({
   // ...
   const isFirstMonth = useMemo(() => {
    if (typeof min === "undefined") return false;
    return dayToYyyymmdd(firstDay) <= min;
  }, [min, firstDay, dayToYyyymmdd]);
  // ...

I am porting project from ESLint to Rome and when I add dependency to the useMemo I got this from ESLint

React Hook useMemo has an unnecessary dependency: 'dayToYyyymmdd'. Either exclude it or remove the dependency array. Outer scope values like 'dayToYyyymmdd' aren't valid dependencies because mutating them doesn't re-render the component  react-hooks/exhaustive-deps

However if I remove it I got error from the Rome.

Expected result

I think the dependency OUTSIDE of the function body is not necessary to specify as dependency and Rome should not require it.

Code of Conduct

  • I agree to follow Rome's Code of Conduct
@peter-goodfill peter-goodfill added the S-To triage Status: user report of a possible bug that needs to be triaged label Jan 5, 2023
@peter-goodfill peter-goodfill changed the title Unnecessary dependency: "This hook do not specify all of its dependencies." but for function defined OUTSIDE of the component function body Jan 5, 2023
@github-actions
Copy link

👋 @rome/staff please triage this issue by adding one of the following labels: S-Bug: confirmed, S-Planned , S-Wishlist or umbrella

@ematipico ematipico removed the S-Stale label Feb 14, 2023
@ematipico ematipico added S-Bug: confirmed Status: report has been confirmed as a valid bug A-Linter Area: linter and removed S-To triage Status: user report of a possible bug that needs to be triaged labels May 8, 2023
@ematipico
Copy link
Contributor

@Conaclos this is still valid, in case you're interested at looking at react hooks rules

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Linter Area: linter S-Bug: confirmed Status: report has been confirmed as a valid bug
Projects
None yet
Development

No branches or pull requests

2 participants