eslint-plugin-no-state-hooks
TypeScript icon, indicating that this package has built-in type declarations

0.1.26 • Public • Published

eslint-plugin-no-state-hooks

Avoid using useState or useReducer

When using an architecture that separates your application state from your UI components (e.g. Flux), it may be desirable to forbid the use of local component state.

Examples

function MyComponent() {
  const [getState, setState] = useState(); // error
  const [state, dispatch] = useReducer(() => {}, undefined); // error
  return <></>;
}

Installation

npm i -D eslint-plugin-no-state-hooks

Usage

Install and enable typescript-eslint with type linting, see:

npm install -D @typescript-eslint/parser@latest @typescript-eslint/eslint-plugin@latest eslint@latest typescript@latest
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "tsconfigRootDir": ".",
    "project": ["./tsconfig.json"]
  },
  "plugins": ["@typescript-eslint"],

Configure the plugin in your .eslintrc:

{
  "extends": ["plugin:no-state-hooks/recommended"]
}

This essentially expands to:

{
  "plugins": ["no-state-hooks"],
  "rules": {
    "no-state-hooks/no-state-hooks": "error"
  }
}

Credit

Inspired by:

Readme

Keywords

none

Package Sidebar

Install

npm i eslint-plugin-no-state-hooks

Weekly Downloads

1

Version

0.1.26

License

MIT

Unpacked Size

16.2 kB

Total Files

12

Last publish

Collaborators

  • gkiely