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

Unexpected warning in react-hooks/exhaustive-deps using optional chaining operator #19083

Closed
jcestibariz opened this issue Jun 5, 2020 · 2 comments

Comments

@jcestibariz
Copy link

This issue is very similar to #18985 but it happens with useCallback instead of useEffect, and the error message is different.

eslint-plugin-react-hooks version: 4.0.4

Steps To Reproduce

The order of reference matters, if you flip the two calls to console.log no error is reported. And as in #18985 replacing ?. with . won't result in an error.

function MyComponent(props) {
  useCallback(() => {
    console.log(props?.foo);
    console.log(props);
  }, [props]);
};
package.json
{
  "name": "bug-react-hooks",
  "version": "1.0.0",
  "description": "",
  "license": "ISC",
  "scripts": {
    "test": "eslint test.js"
  },
  "dependencies": {
    "babel-eslint": "^10.1.0",
    "eslint": "^7.1.0",
    "eslint-plugin-react-hooks": "^4.0.4"
  },
  "eslintConfig": {
    "parser": "babel-eslint",
    "parserOptions": {
      "sourceType": "module"
    },
    "plugins": [
      "react-hooks"
    ],
    "rules": {
      "react-hooks/exhaustive-deps": "warn"
    }
  }
}

The current behavior

The following warning is reported:

5:6  warning  React Hook useCallback has an unnecessary dependency: 'props'. Either exclude it or remove the dependency array  react-hooks/exhaustive-deps

The expected behavior

No warning should be reported.

@jcestibariz jcestibariz added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Jun 5, 2020
@bvaughn bvaughn added Component: ESLint Rules Type: Bug and removed Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug labels Jun 5, 2020
@bvaughn bvaughn changed the title Bug: Take 2: Unexpected warning in react-hooks/exhaustive-deps using optional chaining operator Unexpected warning in react-hooks/exhaustive-deps using optional chaining operator Jun 5, 2020
@koba04
Copy link
Contributor

koba04 commented Jun 6, 2020

This seems to be duplicate of #19061, and #19062 is a fix for this.

@jcestibariz
Copy link
Author

Fixed in v4.0.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants