eslint-plugin-use-selector-with
v0.1.2
Published
ESLint plugin to enforce using `useSelectorWith` when reasonable.
Downloads
1,414
Maintainers
Readme
eslint-plugin-use-selector-with
ESLint plugin for rules around proper useSelectorWith
usage.
Installation
yarn add --dev eslint eslint-plugin-use-selector-with
Usage
Add use-selector-with
to the plugins
section of your ESLint configuration file:
{
plugins: ['use-selector-with'];
}
Rules
Includes two rules, both of which are auto-fixable and have no configuration options:
We recommend extending from plugin:use-selector-with/recommended
to enable both of them:
{
"extends": ["plugin:use-selector-with/recommended"]
}
If you want more fine control over the rules, you may configure them individually per ESLint's Configuring Rules docs:
{
"rules": {
"use-selector-with/prefer-use-selector-with": "warn"
}
}
prefer-use-selector-with
Enforces using useSelectorWith
instead of passing a function expression to useSelector
.
Examples of failing code with this rule:
const value = useSelector((state) => getValueFromState(state, 'id'));
Examples of passing code with this rule:
const value = useSelectorWith(getValueFromState, 'id');
unnecessary-use-selector-with
Enforces using useSelector
instead of useSelectorWith
if there are no args to pass to the selector.
Examples of failing code with this rule:
const value = useSelectorWith(state, getValueFromState);
Examples of passing code with this rule:
const value = useSelector(getValueFromState);