Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

💅 Biomo throw useExhaustiveDependencies error when variable outside the component is used in useMemo #1781

Closed
1 task done
nouman2075 opened this issue Feb 10, 2024 · 0 comments · Fixed by #1966
Closed
1 task done
Labels
A-Linter Area: linter L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug

Comments

@nouman2075
Copy link

Environment information

CLI:
  Version:                      1.5.3
  Color support:                true

Platform:
  CPU Architecture:             aarch64
  OS:                           macos

Environment:
  BIOME_LOG_DIR:                unset
  NO_COLOR:                     unset
  TERM:                         "xterm-256color"
  JS_RUNTIME_VERSION:           "v20.11.0"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         "bun/1.0.26"

Biome Configuration:
  Status:                       Loaded successfully
  Formatter disabled:           false
  Linter disabled:              false
  Organize imports disabled:    false
  VCS disabled:                 false

Workspace:
  Open Documents:               0

Rule name

useExhaustiveDependencies

Playground link

https://biomejs.dev/playground/?code=aQBtAHAAbwByAHQAIAB7ACAAdQBzAGUATQBlAG0AbwAgAH0AIABmAHIAbwBtACAAJwByAGUAYQBjAHQAJwA7AAoAaQBtAHAAbwByAHQAIAB7ACAAQQBjAGMAZQBzAHMAUABvAGwAaQBjAHkATABpAHMAdAAgAH0AIABmAHIAbwBtACAAJwAuAC8AYQBjAGMAZQBzAHMAUABvAGwAaQBjAHkATABpAHMAdAAnADsACgAKAGkAbgB0AGUAcgBmAGEAYwBlACAAQQBjAGMAZQBzAHMAUABvAGwAaQBjAHkARAByAGEAdwBlAHIAUAByAG8AcABzACAAewAKACAAIAByAGUAcwBvAHUAcgBjAGUAOgAgAHMAdAByAGkAbgBnADsACgB9AAoACgBlAHgAcABvAHIAdAAgAGQAZQBmAGEAdQBsAHQAIABmAHUAbgBjAHQAaQBvAG4AIABSAGUAcwBvAHUAcgBjAGUAQwBvAG4AZgBpAGcAdQByAGEAdABpAG8AbgAoAHAAcgBvAHAAcwA6ACAAQQBjAGMAZQBzAHMAUABvAGwAaQBjAHkARAByAGEAdwBlAHIAUAByAG8AcABzACkAIAB7AAoACQBjAG8AbgBzAHQAIAB7ACAAcgBlAHMAbwB1AHIAYwBlACAAfQAgAD0AIABwAHIAbwBwAHMAOwAKAAoACQBjAG8AbgBzAHQAIABvAHAAdABpAG8AbgBzACAAPQAgAHUAcwBlAE0AZQBtAG8AKAAoACkAIAA9AD4AIAB7AAoACQAJAGMAbwBuAHMAdAAgAGMAbwBuAGYAaQBnACAAPQAgAEEAYwBjAGUAcwBzAFAAbwBsAGkAYwB5AEwAaQBzAHQAPwAuAFsAcgBlAHMAbwB1AHIAYwBlAF0AOwAKAAkACQBpAGYAIAAoACEAYwBvAG4AZgBpAGcAKQAgAHIAZQB0AHUAcgBuACAAWwBdADsACgAKACAAIAAgACAAIAAgACAAIAAvAC8AIABTAG8AbQBlACAAYwBhAGwAYwB1AGwAYQB0AGkAbwBuAC4ALgAuAC4ACgAJAAkAcgBlAHQAdQByAG4AIABbAF0ACgAJAH0ALAAgAFsAcgBlAHMAbwB1AHIAYwBlAF0AKQA7AAoACgAJAHIAZQB0AHUAcgBuACAAbgB1AGwAbAA7AAoAfQAKAA%3D%3D

Expected result

useMemo should not include any variable/constant in dependencies array that is declared outside the component of imported from another file.

import { useMemo } from 'react';
import { AccessPolicyList } from './accessPolicyList';

export default function ResourceConfiguration(props: AccessPolicyDrawerProps) {
	const { resource } = props;

	const options = useMemo(() => {
		const config = AccessPolicyList?.[resource];
		if (!config) return [];

                // Some calculation....
		return []
	}, [resource]);

	return null;
}

Throw error:

  1. This hook does not specify all of its dependencies: AccessPolicyList?.[resource]
  2. This hook specifies more dependencies than necessary: resource

In above example, only resourse should be in dependency array

Code of Conduct

  • I agree to follow Biome's Code of Conduct
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Linter Area: linter L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug
Projects
None yet
2 participants