You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

@seiyab/eslint-plugin-react-hooks

Package Overview
Dependencies
1
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@seiyab/eslint-plugin-react-hooks

ESLint rules for React Hooks


Version published
Weekly downloads
807
increased by0.37%
Maintainers
1
Created
Weekly downloads
 

Readme

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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc