How to ensure hooks followed the rules in your project?
React team released an ESLint plugin called eslint-plugin-react-hooks that enforces these two rules. You can add this plugin to your project using the below command,
1 | npm install eslint-plugin-react-hooks@next |
And apply the below config in your ESLint config file,
1 2 3 4 5 6 7 8 9 10 11 | // Your ESLint configuration { "plugins": [ // ... "react-hooks" ], "rules": { // ... "react-hooks/rules-of-hooks": "error" } } |
Note: This plugin is intended to use in Create React App by default.
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.