Using Hooks requires following certain rules
There are certain rules that must be followed when using Hooks, which are used in daily development. These include:
(1) Variables used in the useEffect callback must be declared in dependencies;
(2)Hooks cannot appear in conditional statements, loops, or after returns;
(3)Hooks can only be used in function components or custom Hooks.
React-plugin-react-hooks esLint-plugin-react-hooks eslint-plugin-react-hooks eslint-plugin-react-hooks With this plug-in, if a violation such as a missing dependency definition is found, an error message (similar to a syntax error message) is reported so that it can be easily modified to avoid the incorrect use of Hooks.
Using the step
NPM install eslint-plugin-react-hooks –save-dev
(2) Modify the ESLint configuration file
{
"plugins": [
// ...
"react-hooks"]."rules": {
// ...
// Check the rules for using Hooks
"react-hooks/rules-of-hooks": "error".// Check the declaration of dependencies
"react-hooks/exhaustive-deps": "warn"}}Copy the code
The last
Hope to organize the information to help you, like the words please help to like
If you have any suggestions, feel free to leave them in the comments section
Please also criticize the inadequacies, thank you!