Skip to content

Fix Biome useExhaustiveDependencies error with method references

fix

Biome reports hook dependency more specific than its captures when using obj.method in dependency array

biomereacthookslinting
21 views

Problem

Biome's useExhaustiveDependencies rule flags an error when a method reference like obj.toString or files.map is listed as a hook dependency:

lint/correctness/useExhaustiveDependencies

  This hook specifies a dependency more specific than its captures: cacheControl.toString
  This hook does not specify its dependency on cacheControl.

The code listing a method reference in the dependency array:

const onUpload = useCallback(async () => {
  const options = {
    cacheControl: cacheControl.toString(),
    upsert,
  };
  // ...upload logic
}, [files, path, bucketName, cacheControl.toString, upsert]);
//                           ^^^^^^^^^^^^^^^^^^^^^^ Biome error

Solution

Option 1: Use the object itself as the dependency (recommended)

const onUpload = useCallback(async () => {
  const options = {
    cacheControl: cacheControl.toString(),
    upsert,
  };
  // ...upload logic
}, [files, path, bucketName, cacheControl, upsert]);
//                           ^^^^^^^^^^^^^ object, not method

Option 2: Extract the value before the hook

const cacheControlValue = cacheControl.toString();

const onUpload = useCallback(async () => {
  const options = {
    cacheControl: cacheControlValue,
    upsert,
  };
  // ...upload logic
}, [files, path, bucketName, cacheControlValue, upsert]);

Why It Works

React's dependency comparison uses Object.is on each item in the dependency array. When you list obj.method, React compares the method reference itself, which is more specific than the object -- if the object changes identity but the method reference somehow stays the same (or vice versa), React will make wrong decisions about re-running the effect. Biome catches this because the hook body captures obj (by calling obj.method()), but the dependency array lists only obj.method. Listing the object itself ensures the hook re-runs whenever the object changes, which is what you actually depend on.

Context

  • Biome 1.x+ with the lint/correctness/useExhaustiveDependencies rule
  • Also applies to patterns like array.map, array.filter, ref.current.method
  • The ESLint react-hooks/exhaustive-deps rule has similar but not identical behavior
  • If the value is a primitive (string, number), extracting it before the hook (Option 2) avoids unnecessary re-renders when the object reference changes but the value stays the same
  • Run biome check --write --unsafe to auto-fix, but review the diff -- the unsafe fix may not choose the best option
About this share
Contributormblode
Repositorymblode/shares
CreatedFeb 9, 2026
Environmentreact
View on GitHub