question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: eslint-react-hooks asking (exhaustive-deps) asking for the full object instead of the property that is being used on useEffect

See original GitHub issue

React version:

"react": "^16.13.1",
"react-dom": "^16.13.1",

devDependencies
"eslint": "^7.0.0",
"eslint-import-resolver-alias": "^1.1.2",
"eslint-module-utils": "^2.6.0",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-react": "^7.19.0",
"eslint-plugin-react-hooks": "^4.0.0",

Steps To Reproduce

This code:

function MyComponent() { 

  const lastPathname_ref = useRef(null);
  const location = {pathname: ""};

  useEffect(() => {
      lastPathname_ref.current = location.pathname;
  },[]);
}

Link to code example:

https://codesandbox.io/s/solitary-currying-htsp3

The current behavior

This very same code is asking for different variables in the dependency array:

On CodeSandbox, it’s asking for location.pathname, which is correct and is the intended behavior of my useEffect.

image

On my local environment (using the versions I’ve mentioned above), it’s asking for the full location object. Which I think it’s not correct, and that is not what I need.

image

I don’t know what versions the CodeSandbox environment is using.

The expected behavior

It should be asking for the location.pathname property, instead of the full location object.

NOTE

This issue seems to be different than https://github.com/facebook/react/issues/16265 , because that one is caused when you call a method straight from the object, without destructuring it first. This issue is happening when using a property, not a method.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
DavidHenri008commented, May 15, 2020

I also have this behavior since upgrading to “eslint-plugin-react-hooks”: “4.0.2”, from version 4.0.0.

In my case:

useEffect(() => {
    const newSelectedVersion = globalPackage?.version || globalPackage?.versions[0].version;
    setSelectedVersion(newSelectedVersion);
  }, [globalPackage]);

Produce the following warning message:

React Hook useEffect has missing dependencies: 'globalPackage?.version' and 'globalPackage?.versions'. Either include them or remove the dependency array  react-hooks/exhaustive-deps
0reactions
maksnestercommented, Nov 17, 2022

=> Found “eslint-plugin-react-hooks@4.2.0”

Seems like this issue is still here.

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

Warning for 'exhaustive-deps' keeps asking for the full 'props ...
Is asks me that I'm missing the full props object. And if I add [props.myProp] to the array, the warning DOES NOT go...
Read more >
Understanding the React exhaustive-deps linting warning
The count variable that renders in the component updates when you click the button, but the value that gets logged in the useEffect...
Read more >
Warning for 'exhaustive-deps' keeps asking for the full 'props ...
Coding example for the question Warning for 'exhaustive-deps' keeps asking for the full 'props' object instead of allowing single 'props' methods as ...
Read more >
useHooks - Easy to understand React Hook recipes
We bring you easy to understand React Hook code recipes so you can learn how React hooks work and feel more comfortable writing...
Read more >
searchprops' is missing in props validation - You.com - You.com
facebook/reactWarning for 'exhaustive-deps' keeps asking for the full 'props' object instead of allowing single 'props' properties as dependencies#16265.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found