Skip to content

Enforce custom useAppDispatch and useAppSelector hooks instead of defaults from react-redux

License

Notifications You must be signed in to change notification settings

Manku27/eslint-plugin-redux-tsc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

eslint-plugin-redux-tsc

Usage

npm install eslint-plugin-redux-tsc --save

Or

yarn add --dev eslint eslint-plugin-jest

In .eslintrc

plugins : [
            // other plugins,
            "redux-tsc"
          ],
rules :   {
           // other rules,
           "redux-tsc/enforce-hooks": "error",
           "redux-tsc/restrict-react-redux": "error"
          }

Output

Linthook

&&

LintImport

Why

Redux strongly recommends using typed hooks when using with typescript projects.

Following their documentation , we add these Typed-hooks which look something of the sort of useAppSelector and useAppDispatch which are to be used against the useSelector and useDispatch, for React via react-redux.

One way, the documentation suggests is to restrict imports via @typescript-eslint/eslint-plugin, which I find verbose. I have wrapped on it to extend import restriction while also adding lint errors on the hook too.

About

Enforce custom useAppDispatch and useAppSelector hooks instead of defaults from react-redux

Resources

License

Stars

Watchers

Forks