🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

@seiyab/eslint-plugin-react-hooks

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@seiyab/eslint-plugin-react-hooks

ESLint rules for React Hooks

4.5.1-beta.0
latest
Source
npm
Version published
Weekly downloads
2.2K
-55.64%
Maintainers
1
Weekly downloads
 
Created
Source

@seiyab/eslint-plugin-react-hooks

This is alternative to eslint-plugin-react-hooks because of https://github.com/facebook/react/issues/16265

Installation

Assuming you already have ESLint installed, run:

# npm
npm install @seiyab/eslint-plugin-react-hooks --save-dev

# yarn
yarn add @seiyab/eslint-plugin-react-hooks --dev

Then extend the recommended eslint config:

{
  "extends": [
    // ...
    "plugin:@seiyab/react-hooks/recommended"
  ]
}

Custom Configuration

If you want more fine-grained configuration, you can instead add a snippet like this to your ESLint configuration file:

{
  "plugins": [
    // ...
    "@seiyab/eslint-plugin-react-hooks"
  ],
  "rules": {
    // ...
    "@seiyab/react-hooks/rules-of-hooks": "error",
    "@seiyab/react-hooks/exhaustive-deps": "warn"
  }
}

Advanced Configuration

additionalHooks

exhaustive-deps can be configured to validate dependencies of custom Hooks with the additionalHooks option. This option accepts a regex to match the names of custom Hooks that have dependencies.

{
  "rules": {
    // ...
    "@seiyab/react-hooks/exhaustive-deps": ["warn", {
      "additionalHooks": "(useMyCustomHook|useMyOtherCustomHook)"
    }]
  }
}

We suggest to use this option very sparingly, if at all. Generally saying, we recommend most custom Hooks to not use the dependencies argument, and instead provide a higher-level API that is more focused around a specific use case.

ignoreThisDependency

You may find exhaustive-deps requires entire props if you use something like props.doSomething() in hooks. This is intended behavior because props is referred as this by doSomething. You can resolve it by destructuring as exhaustive-deps suggests.

However, in some cases, you may want to avoid destructuring because of your coding style or conflict with no-shadow. In the case, ignoreThisDependency may help.

{
  "rules": {
    // ...
    "@seiyab/react-hooks/exhaustive-deps": ["warn", {
      "ignoreThisDependency": "props"
    }]
  }
}

Valid options are never (default behavior), props, always.

Valid and Invalid Examples

Please refer to the Rules of Hooks documentation and the Hooks FAQ to learn more about this rule.

License

MIT

Keywords

eslint

FAQs

Package last updated on 15 Nov 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts